Pygame Window Closing Automatically

  1. Dec 02, 2020 Command to install pygame on windows based system: pip install pygame There are 7-basic steps to displaying Text on the pygame window: Create a display surface object using display.setmode method of pygame. Create a Font object using fony.Font method of pygame. Create a Text surface object i.e.surface object in which Text is drawn on it.
  2. I always use file explorer (used to be windows explorer). Anyhow, after opening the file explorer, it closes by itself after 30 minutes or so. Any solution of disabling it? I have Windows 10 Pro.

Everything in Pygame Zero is optional; a blank file is a valid Pygame Zero script! You can quit the game by clicking on the window’s close button or by pressing Ctrl-Q (⌘-Q on Mac). If the game stops responding for any reason, you may need to terminate it by pressing Ctrl-C in your Terminal window. Apr 07, 2020 The resizing thing I tested also on pygame 1.9.4 and 1.9.5 and it's the same. What I wish is to draw on the window when it is resized to a larger size, but I can't seem to do it. I also saw people doing this: if event.type pygame.VIDEORESIZE: window = pygame.display.setmode((event.w, event.h), pygame.RESIZABLE).

pygame window closes immediately
pygame window not responding when closing
pygame tutorial
pygame events
pygame window not closing mac
pygame.error: display surface quit
module 'pygame' has no 'quit' member
pygame documentation

I just spent a fair amount of time finding a 64-bit installation of pygame to use with python 3.3, (here) and now am trying to make a window. However, although the window opens up fine it does not close when it hit the x button. In fact, I have to close IDLE to close the window. I am running a 64 bit version of Win 7. Here is my code:

When I append

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(). I have personally run into problems (was on a unix system though) where this still did not close the window properly. The solution was to add pygame.display.quit() specifically before pygame.quit(). That should not be necessary as far as I can tell, and I'm afraid I don't know why that solved the issue but it did.

Could someone help me out with closing a pygame window?, QUIT: pygame.display.quit(), sys.exit() score += 1 #Check for arrow key presses, For now I just want to know what the code would be to close the window using​ The class method on_execute calls first the on_init method where pygame is intialized and the display mode is set, then the event loop is executed where pygame events are process and the current frame is rendered. Only if an pygame.QUIT event is catched the event loop is exited and the pygame.quit() is called to cleanup the pygame environment. Then also the applications ends.

if you want to make pygame close when window button x is pressed, put the code like this:

We put exit() after pygame.quit(), because pygame.quit() makes the system exit and exit() closes that window.

PyGame does not close when I press the close button, pygame.display.set_caption( 'Alien Invasion' ). # Set the I have to close the IDLE shell itself in order to close the window. I'm not sure why the We will: Create a Pygame window Stop the window from immediately disappearing Close the window in response to a quit event Change the title and background colour of the window

Not sure but try this Because you code runs fine on my system after I add pygame.quit() at the end

Its perhaps because as Idle is made on Tkinter and thus Tkinter and Pygame main loop do not have a mutual understanding.Your code will run very well on command prompt though.

Creating a Pygame window, Closing the window. We want our window to persist until the user chooses to closes it. To achieve this, we monitor user inputs (known as ' Most pygame tutorials seem to suggest exiting by calling pygame.quit () and then sys.exit (). I have personally run into problems (was on a unix system though) where this still did not close the window properly. The solution was to add pygame.display.quit () specifically before pygame.quit ().

This was the final code that worked for me on OSX whilst keeping the kernel alive on Jupyter. EDIT - it does still crash the kernel sometimes :-(

Also needed to downgrade ipython to get rid of some magic alias warning messages using:

apparently that issue is due to be fixed in ipython 7.6.0

3.6: The QUIT Event and pygame.quit() Function, 05, DISPLAYSURF = pygame.display.set_mode(( 400 , 300 )) Normally it doesn't really matter since Python closes it when the program exits Could someone help me out with closing a pygame window? I'm following along with a book I'm reading and one of the examples involves the module pygame. I got the code to run as it's intended but I can't figure out how to close the window when I'm done.

Suffered the same issues on Python 3.7.4 while running it from in IDE (Spyder 3.3.6). In my case the pygame.quit() would not completely close the program. Nonetheless, adding quit() or exit() did the trick for me!

Chapter 2 - Pygame Basics, Our first program made with Pygame is a small program that makes a window that Normally it doesn't really matter since Python closes it when the program If you run pygame scripts in an interactive console, the program needs to reach pygame.quit () or the pygame window will freeze and you have to force shut it. This also happens when an error occurs before the pygame.quit ().

Closing Pygame Window, Closing Pygame Window. pygame window closes immediately pygame.error: display surface quit pygame tutorial pygame events module 'pygame' has no 'quit​ Hey there. Working on a simple version of pong as my first program and I'm following this tutorial (not line for line, but close). But when the paddle moves and reaches the bottom of the window, the window closes (crashes?). It doesn't happen when moving up and hits the upper bound but always does close when the lower bound is reached.

Pygame Window Closing AutomaticallyAutomatically

FrequentlyAskedQuestions, In IDLE why does the Pygame window not close correctly?¶. This is caused and if you also want to close the window on exceptions you might solve it like this​:. Pygame can only have a single display active at any time. Creating a new one with pygame.display.set_mode() will close the previous display. If precise control is needed over the pixel format or display resolutions, use the functions pygame.display.mode_ok(), pygame.display.list_modes(), and pygame.display.Info() to query information about the display.

pygame.QUIT Python Example, def run(self): '' Initialize pygame, open window and start game loop. '' pygame.​init() clock = pygame.time.Clock() self.game_canvas.open() self.screen PyGame, window is not closing, tut not helping. Python Forums on Bytes.

Comments
  • Try running the code from command prompt and see if the problem persist
  • Have you looked at the relevant question on the pygame FAQ?
  • what pygame version are you using?
  • @Alfgaar To be honest, I don't remember. It was a while ago :)
  • pygame.init() initializes all pygame modules (display, mixer, font, etc.) and pygame.quit() does the contrary, closes all modules. one can initalize a module per turn, if you want to use only display you do pygame.display.init(), no real need to call pygame.init... but, according to what you said, pygame.quit is faillling on closing the display module....
  • Thank the lord, finally an answer that works! Been looking everywhere for an answer that wasn't just restating the pygame docs method. Personally this got rid of the window that was otherwise frozen, but the process still hung on pygame.quit(). I initialized only the display using @Alfgaar's method, and then removed pygame.quit() altogether to finally close it all the way.
  • The except SystemExit works, but it still closes IDLE. Also, when I open command prompt it returns the error 'pygame.error:video system not initialized.' Any idea how to solve this? And by the way, thanks for the help.
  • Well I cant figure out why is it closing the IDLE (not in my case). Also mind that it may be the problem that you are replacing your code pygame.QUIT with pygame.quit(). pygame.quit() is a function that closes pygame (python still running) While pygame.QUIT just checks if pygame is running or not.
  • I put pygame.quit() function after the while loop to make sure that pygame is not running after the while loop. do not use it while checking ( if-else statements).

Hot Questions

Hi everyone, from this post we will start learning PyGame. And programming games are real fun, that is why I am here with this PyGame Tutorial for Beginners.

If you are interested in learning game development with python, and you have absolutely no idea about it, then this is the right place for you. I am assuming the readers here are no knowledge of pygame, but you must know the basics of python Ok.

So, let’s start with the very obvious question.

Contents

  • 5 Installation
    • 5.1 Installing Python

What is PyGame?

PyGame is a set of python modules, and these modules are specially designed for writing or coding games. For more information about PyGame you can visit the Official PyGame Website.

What kind of games we can make with PyGame?

You might be thinking what kind of games you can make with PyGame. And honestly speaking it is good for 2D games. And if you are new to game programming then PyGame is good to get started.

You can check this link to see the games that are built with PyGame.

Who can follow this PyGame Tutorial for Beginners?

Any one with the basic knowledge of python can follow this tutorial. You do not need to be an expert or advanced python geek, just a basic understanding of python is more than enough to follow this.

Tools Required

For getting started you just need a simple code editor, notepad++, Visual Studio Code anything is more than enough. But you can also go with some powerful IDE, for example my favourite, JetBrains PyCharm. The community edition is also very very powerful and it is absolutely free.

Installation

Pygame quit

Now we have had enough discussion and now we should start the learning part. So we will start from the Installation of PyGame. As this series is called PyGame Tutorial for Beginners, we will cover the installation as well ;).

But before installing PyGame you also need Python and yes it is something obvious.

Installing Python

  • Go to Python’s Website. And download the Python according to your system. In my case I am using Python 3.7, 64bit windows installer.
  • So you just need to download the executable installer (in case of windows) and then you can install it. The installation process is same as you install any other application in your windows computer.

Setting Up Environment Variables

  • Once you have finished installing Python, you also need to setup environment variables. The default installation directory is

C:Users<your user name>AppDataLocalProgramsPythonPython37

  • In the search menu, write environment
  • Select Edit the system environment variables. It will open a new window, from here in the bottom you will see a button named Environment Variables…, click on it and it will open the following window.
  • In the bottom box (System variables) click on New…
  • Here you need to write “Path” in Variable name and in Variable value I have the path for the Python installation directory and the Scripts directory which is inside the Python Installation directory, separated by a semi colon (;).
  • Now apply the changes and path are set.
  • To confirm it you can try running python command in command prompt.

Installing PyGame

  • I am using a 64bit, Python but the problem is we do not have an official 64bit PyGame. But we have UnOfficial 64bit PyGame so this is what we will be using.
  • Click on this link, here you will find the unofficial 64bit PyGame Windows Binary.
  • I am using the highlighted one.
  • Now to install PyGame open command prompt and navigate to the directory where you have downloaded the .whl file in command prompt. (In my case it is in my desktop).
  • Now, first you need to install wheel, for this run the following command in command prompt.
2
pip install wheel
  • And it will install wheel.

Pygame Window Closing Automatically Lock

  • Now we will run the following command.
2
pip install pygame-1.9.3-cp37-cp37m-win_amd64.whl
  • And also make sure the PyGame WHL file exist in the current directory.

The IDE or Code Editor

Pygame Window Closing Automatically Start

Now, this is completely your personal choice, but I think I should tell you what I am using. Python also have IDLE, its own inbuilt editor but I will be using Visual Studio Code, it is again an absolutely free tool.

But yes, it is not necessary that you should also use Visual Studio Code, you can use whatever editor you want to use.

Creating our Game Window

Now let’s do a little coding, and create our very first game window. Excited?. Yes. So let’s begin.

  • Create a file named game.py anywhere in your computer. (But it is a good practice to organize your files by keeping them in separate folder, so I would tell that create a folder for your game project).
  • Inside the file game.py write the following code.