You should stop your main loop when you want to exit the game.
My suggestions, either of
- call
exit()
afterpygame.quit()
- set
finish = True
andstart = False
(though due to some indentation issues with your pasted code it’s not possible to tell that this would actually work)
You should call pygame.quit()
only when you want to terminate your Python session.
My suggestion: if you want to call game()
more than once, e.g. in an interactive session, you should remove the call to pygame.quit()
inside game()
. This function uninitializes pygame and naturally all attempts to call its functionality will fail then.
Related Posts:
- Process finished with exit code -1073741515 (0xC0000135)
- ImportError: No module named ‘pygame’
- ImportError: No module named ‘pygame’
- pygame.error: video system not initialized
- pygame.error: video system not initialized
- How to draw a circle in PyGame?
- TypeError: object of type ‘int’ has no len() – Python/Pygame
- Pygame Drawing a Rectangle
- How do I detect collision in pygame?
- How to display text in pygame?
- How to get keyboard input in pygame?
- Countdown timer in Pygame
- pygame clock.tick() vs framerate in game main loop
- Start with pyglet or pygame?
- Pygame mouse clicking detection
- How can I create a text input box with Pygame?
- How do I maximize the display screen in PyGame?
- How to install PyGame on Python 3.4?
- How to use pygame.KEYDOWN to execute something every time through a loop while the key is held down?
- How to clear up screen in pygame?
- Installation of pygame with Anaconda
- How do I rotate an image around its center using Pygame?
- How to add a background image into pygame?
- SyntaxError: unexpected EOF while parsing
- Why am I seeing “TypeError: string indices must be integers”?
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How to emulate a do-while loop?
- How to prettyprint a JSON file?
- How to install pip with Python 3?
- pip not recognised as an internal or external command
- Import Error: No module named numpy
- Extract file name from path, no matter what the os/path format
- Importing requests module does not work
- Converting string into datetime
- How do I read CSV data into a record array in NumPy?
- How to normalize a NumPy array to a unit vector?
- Local variable referenced before assignment?
- Clickable link inside message discord.py
- DataFrame constructor not properly called! error
- OSError: [WinError 193] %1 is not a valid Win32 application
- How to download a file over HTTP?
- Pandas how to use pd.cut()
- What is the difference between list and list[:] in python?
- How to Read .txt in Pandas
- Why am I getting AttributeError: Object has no attribute?
- OSError [Errno 22] invalid argument when use open() in Python
- SBOX_FATAL_MEMORY_EXCEEDED error shown when Chromedriver turned 1800-1900 pages using Selenium
- Pinging servers in Python
- How can I use Python to get the system hostname?
- What is the difference between Anaconda and Pycharm?
- Add Legend to Seaborn point plot
- How to pass arguments to a Button command in Tkinter?
- How to remove specific substrings from a set of strings in Python?
- How do I install the yaml package for Python?
- Python: Array v. List
- How to pretty print nested dictionaries?
- Is there a linked list predefined library in Python?
- return, return None, and no return at all?
- What does [:-1] mean/do in python? [duplicate]
- Displaying better error message than “No JSON object could be decoded”
- How do I check if a string is a number (float)?
- How are Pipfile and Pipfile.lock used?
- Create a .csv file with values from a Python list
- Why matplotlib does not plot?
- Where do I call the BatchNormalization function in Keras?
- unittest Vs pytest
- Add single element to array in numpy
- ‘pip install’ fails for every package (“Could not find a version that satisfies the requirement”) [duplicate]
- Spyder Not Launching
- How do I profile memory usage in Python?
- Wait until page is loaded with Selenium WebDriver for Python
- What is the meaning of ‘for _ in range()
- How do I check if there are duplicates in a flat list?
- super(type, obj): obj must be an instance or subtype of type
- What does “hashable” mean in Pytho
- Python multiprocessing.Pool: AttributeError
- Convert string to ASCII value python
- “Divide by zero encountered in log” when not dividing by zero
- How to include external Python code to use in other files?
- How to print multiple lines of text with Python
- How to get a function name as a string?
- Substitution Cipher Python
- Is there a Python equivalent of the C# null-coalescing operator?
- Python 3.6 import requests
- Tensorflow 2.0 – AttributeError: module ‘tensorflow’ has no attribute ‘Session’
- What is key=lambda
- Extract a part of the filepath (a directory) in Python
- Python 3.5.1 urllib has no attribute request
- Rotating a two-dimensional array in Python
- TypeError: sequence item 0: expected string, int found
- Why am I getting this unexpected keyword argument TypeError?
- Create numpy matrix filled with NaNs
- Python: Convert timedelta to int in a dataframe
- Can’t concat bytes to str
- cmake error ‘the source does not appear to contain CMakeLists.txt’
- ubuntu /usr/bin/env: python: No such file or directory
- Python MySQLdb not importing
- Write a program that asks the user to enter five test scores. Correspond it to a letter grade
- Simplify Chained Comparison
- How to get POSTed JSON in Flask?