The best SE to post this would probably be stack overflow. There's quite a few pygame questions.
Do you always require sudo to run, or only if using ssh? On Jun 30, 2017 1:29 PM, "Роман Мещеряков" <roman.mescherya...@gmail.com> wrote: > Hi all, > > In my Python application running on Raspberry Pi under Raspbian I use > Pygame to display some software-generated images via framebuffer. I don’t > need any input from mouse, keyboard or any other devices, all I need is a > convenient way of using framebuffer. > > > > I initialize Pygame in the following way: > > > class FramebufferStaticImage(object): > > > > black = (0, 0, 0) > > white = (255, 255, 255) > > > > _ENV_VAR_DISPLAY = "DISPLAY" > > _instance = None > > > > def __init__(self, log): > > "Ininitializes a new pygame screen using the framebuffer" > > # Based on "Python GUI in Linux frame buffer" > > # http://www.karoltomala.com/blog/?p=679 > > if FramebufferStaticImage._instance != None: > > raise Exception("No more than 1 instance of > FramebufferStaticImage is allowed!") > > FramebufferStaticImage._instance = self > > self._log = log > > self._log.info("[fb_static_image] Init: entered") > > self._screen = None > > > > # Try ensure using framebuffer and not X11 display even if it > exists > > if self._ENV_VAR_DISPLAY in os.environ: > > del os.environ[self._ENV_VAR_DISPLAY] > > > > os.putenv('SDL_FBDEV', '/dev/fb0') > > os.putenv('SDL_VIDEODRIVER', 'fbcon') > > os.environ['SDL_NOMOUSE'] = '1' > > #### os.putenv('SDL_NOMOUSE', '1') > > self._log.debug("Current environment is: {env}", env = os.environ) > > import pygame > > pygame.display.init() > > > > self._width = pygame.display.Info().current_w > > self._height = pygame.display.Info().current_h > > self._log.info("[fb_static_image] Framebuffer size: {width} x > {height}", > > width = self._width, height = self._height) > > self._screen = pygame.display.set_mode( > > (self._width, self._height), pygame.FULLSCREEN) > > # Clear the screen to start > > self._screen.fill(self.black) > > # Initialise font support > > pygame.font.init() > > # Render the screen > > pygame.display.update() > > self._log.info("[fb_static_image] Init: leaving") > > > > > Problem #1: I have mouse pointer at the top left corner of Pygame-drawn > images. I want mouse pointer to be hidden. > > I know that I can disable mouse pointer using pygame.mouse.set_visible, > but here comes > > Problem #2: I have to run my application with sudo in order for pygame to > not raise “unable to open a console terminal” exception. But I want to run > my application without root rights, because this increases my application’s > security. > > There are some posts on forums that recommend setting SDL_NOMOUSE=1 > environment variable before initializing pygame which should skip mouse > initialization and maybe make it possible to get rid of sudo, but this > doesn’t work for me: I still need to use sudo and mouse pointer is still > there. > > If this makes any difference, I have no mouse or keyboard attached to the > Raspberry Pi, I connect to it using SSH. > > I use > > Pygame version 1.9.2~pre~r3348-2~bpo8+rpi1 > > libsdl-image1.2 version 1.2.12-5+b1 > > libsdl1.2debian version 1.2.15-10+rpi1 > > > > Does SDL_NOMOUSE work for anyone using recent Pygame versions? > > Is it possible to skip mouse initialization in Pygame? > > P.S. This question was originally posted on StackExchange > <https://raspberrypi.stackexchange.com/questions/69007/how-to-completely-disable-mouse-in-pygame>, > but it seems I chose the wrong section. For this reason or another, I > haven’t got any straight answer yet, so I write here and hope for the best > :) >