O
O
OccamaRazor2017-09-20 15:43:40
Python
OccamaRazor, 2017-09-20 15:43:40

Is it possible to use the pygame library to move the window smoothly with the keys?

I wanted to make it so that when a certain key is pressed, the window moves in a certain direction continuously while the key is pressed, but it does not work to make a cycle, either infinite or moving with one click.
When handling a keypress event, the window expands or shrinks but does not change its position using os.environ['SDL_VIDEO_WINDOW_POS']

pressed = pygame.key.get_pressed()
           if pressed[pygame.K_KP2]:
                self.x += 10
                os.environ['SDL_VIDEO_WINDOW_POS'] = "%i,50" % self.x
                DISPLAY = pygame.display.set_mode((self.x, self.y), pygame.NOFRAME)
            if pressed[pygame.K_KP8]:
                self.x -= 10
                os.environ['SDL_VIDEO_WINDOW_POS'] = "%i,50" % self.x
                DISPLAY = pygame.display.set_mode((self.x, self.y), pygame.NOFRAME)
            if pressed[pygame.K_KP4]:
                self.y += 10
                os.environ['SDL_VIDEO_WINDOW_POS'] = "50,%i" % self.y
                DISPLAY = pygame.display.set_mode((self.x,self.y), pygame.NOFRAME)
            if pressed[pygame.K_KP6]:
                self.y -= 10
                os.environ['SDL_VIDEO_WINDOW_POS'] = "50,%i" % self.y
                DISPLAY = pygame.display.set_mode((self.x,self.y), pygame.NOFRAME)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question