Contents
Why is my Pygame window not closing?
Answer #1: The window now persists whilst ‘running’ is equal to True, which it will be until you close the window (by clicking the X). Note that if you use an IDE for Python programming, then it may interfere with Pygame. If so, adding pygame. quit() should solve the problem.
How do I close a Pygame window?
Call pygame. quit() to shut down pygame (this includes closing the window) Call sys. exit() to shut down the program (this exits the infinite loop)
How do you make the Pygame window always on top?
3 Answers. Now to put a window on top, simply call onTop(pygame. display. get_wm_info()[‘window’]) to handle your pygame window.
What does pygame init () return?
1 Answer. pygame. init() initialize all imported pygame modules. No exceptions will be raised if a module fails, but the total number if successful and failed inits will be returned as a tuple.
Inside your main program loop, make a new event. key if statement for whichever key you want the player to press to restart the game, then call main() inside the if statement. This will reset everything back to square 1.
Why does pygame.quit not close the window?
It still doesn’t close. My only guess would be that pygame.quit might go inside one of the loops, but even if that were resolved I would greatly prefer being able to close the window when I want to. Most pygame tutorials seem to suggest exiting by calling pygame.quit () and then sys.exit ().
Why does Pygame generate window of 500 width and 500 height?
It generates a window of 500 width and 500 height 2) pygame.event.get () is a generates a list of event but not all event classes have .key method for example mouse motion. Thus, change all .key event handling codes such as
Why is the Pygame window not responding to newposition?
Also, you have defined newposition (), but have not called it. Also, randx and randy would not be accessible from outside of the function, because the would be local to it. You simply forgot to update the pygame display with your modifications to it.