6

Basically I have a loop (tick, set_caption, screen_fill, event.get(), send_frame_event, flip, repeat)

When I drag the window around on windows 7, the loop stops looping, I ended up stuck in pygame.event.get(), I have tried to define certain events only for get e.g. get([pygame.QUIT]) to no avail.

Simply calling pygame.event.clear() has the same freeze effect when dragging/moving the window.

Is there a workaround?

Not full code, but should be enough:

def start(self):
    self.running = True
    Clock = pygame.time.Clock()
    while self.running:
        self.p += 25
        tickFPS = Clock.tick(self.fps)
        pygame.display.set_caption("Press Esc to quit. FPS: %.2f" % (Clock.get_fps()))
        self.screen.fill([self.p&0xFF,(255-self.p)&0xFF,255])
        self.handleEvents()
        self.raiseEvent("updateFrame")
        pygame.display.flip()
def handleEvents(self):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            self.running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                self.running = False

full code at: http://pastie.org/private/wm5vqq3f7xe0xlffy1fq

  • It is a good practice to put `pygame.event`s inside a while True loop in the main body. – hjpotter92 Apr 12 '12 at 11:08
  • 3
    They effectively are. And doing so makes no difference. Unless you mean inside another thread? – Matthew Parlane Apr 12 '12 at 11:58
  • I have this issue when calling this python.event.get() inside a function in a while loop. If I move the BASH shell the events are no longer printed to the shell. – user_loser Jun 13 '21 at 04:58

2 Answers2

1

Try placing a call to pygame.event.pump() inside your mainloop (or handleEvents function)

jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • "This function is not necessary if your program is consistently processing events on the queue through the other pygame.event functions." http://www.pygame.org/docs/ref/event.html#pygame.event.pump I will try it when I get home for completeness sake though. – Matthew Parlane Apr 12 '12 at 20:34
  • That is why I wrote "try" - I had seem some erratic behavior and differences between different systems when not calling event.pump - so I got used to always place a call to it. – jsbueno Apr 13 '12 at 02:40
  • This did not solve my problem. Even after putting this in the algorithm if I move the shell around and then start clicking buttons again the events are no longer picked up. :/ – user_loser Jun 13 '21 at 04:59
0

No idea if this will help or not:

I realize the problem is with moving the window window, not with re-sizing the window. Perhaps there is some similarity between moving and re-sizing?

I found this in the documentation on re-sizing:

Then the display mode is set, several events are placed on the pygame event queue. pygame.QUIT is sent when the user has requested the program to shutdown. The window will receive pygame.ACTIVEEVENT events as the display gains and loses input focus. If the display is set with the pygame.RESIZABLE flag, pygame.VIDEORESIZE events will be sent when the user adjusts the window dimensions. Hardware displays that draw direct to the screen will get pygame.VIDEOEXPOSE events when portions of the window must be redrawn.

and:

Note that when the user resizes the game window, pygame does not automatically update its internal screen surface. You must call set_mode() every time VIDEORESIZE is sent. This really should be more clear in the documentation.

Perhaps when moving the game window, something similar happens?

Rusty Rob
  • 16,489
  • 8
  • 100
  • 116