Python Forum
Pygame in 90 Minutes - For Beginners syntax issues
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pygame in 90 Minutes - For Beginners syntax issues
#4
You should write programs in a file instead typing them in the Python interactive interpreter.

This is what you file would look like. I fixed and commented some errors/inconcistencies.
import pygame

WIDTH, HEIGHT = 900, 500
WIN = pygame.display.set_mode((WIDTH, HEIGHT))

# Should have 1 or two blank lines before a function
def main():
    run = True
    while run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False  # Should have 1 space before and after =
    pygame.quit()

# You had an indentation error
if __name__ == "__main__":   # Double underscores.  You had single
    main()  # Function name is lower case.  You called Main()
If the file is named "mypygame.py" you run the file like this:
Output:
python mypygame.py' pygame 2.1.3.dev8 (SDL 2.0.22, Python 3.11.1) Hello from the pygame community. https://www.pygame.org/contribute.html
Depending on what OS you are using, you might have to type "python3 mypygame,py"
GoldenHarvey likes this post
Reply


Messages In This Thread
RE: Pygame in 90 Minutes - For Beginners syntax issues - by deanhystad - Jun-08-2023, 11:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Beginners to share pygame project? michael1789 4 3,231 Dec-04-2019, 07:17 AM
Last Post: michael1789
  [PyGame] Python pygame hangs up after 40 minutes chileflora 10 4,912 Jul-28-2019, 01:30 AM
Last Post: chileflora
  Beginners question Youmanity 4 3,920 Apr-08-2018, 07:02 PM
Last Post: Youmanity

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020