Python Forum
question about my pygame code for space shooter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
question about my pygame code for space shooter
#1
Hi, I am not sure why when I go and run my code I am getting these two errors:
Terminal Output:
"File "c:\Users\Timothy Han\Documents\Python Projects\Pygame\PygameForBeginners-main\Assets\Two_Player_Space_Shooter.py", line 18, in <module>
main()

File "c:\Users\Timothy Han\Documents\Python Projects\Pygame\PygameForBeginners-main\Assets\Two_Player_Space_Shooter.py", line 12, in main
if event.type == pygame.QUIT():
TypeError: 'int' object is not callable"

Also, the game window immediately opens and closes for some reason. I know that I set my while loop to 'True' until the player closes or exits out the game window. However, the game window automatically closes by itself real fast for some reason. Not sure why is that. Any suggestions or help would be greatly appreciated! Thanks!

import pygame 

WIDTH, HEIGHT = 900, 500
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("First Pygame!")

def main():

    done = True
    while done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT():
                done = False
    
    pygame.quit()

if __name__ == "__main__":
    main()
Reply


Messages In This Thread
question about my pygame code for space shooter - by Than999 - Feb-07-2022, 12:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  question about my Pygame code Than999 2 1,704 Feb-06-2022, 10:03 PM
Last Post: Than999
  [PyGame] Problems with jump code in pygame Joningstone 4 5,400 Aug-23-2021, 08:23 PM
Last Post: deanhystad
  Distributing Python/Pygame code with CX_Freeze jfng75 2 2,827 Jan-11-2021, 10:23 PM
Last Post: snippsat
Video [PyGame] Space Invaders in PyGame Russ_CW 5 5,012 Nov-22-2020, 12:21 PM
Last Post: Russ_CW
  My Pygame Code always says "(Not responding") noodlespinbot 3 8,153 Feb-29-2020, 10:50 PM
Last Post: Windspar
  [pygame] Improvement with code SheeppOSU 1 2,425 Jul-24-2019, 11:09 AM
Last Post: metulburr
  [PyGame] Beginning PyGame question about "self" jakegold98 2 3,199 Dec-09-2017, 12:51 AM
Last Post: metulburr
  Python Pygame code help Trajme 1 4,047 Dec-07-2017, 04:55 PM
Last Post: nilamo
  Appropriately delay this PyGame code kleynah22 2 4,406 Nov-09-2017, 02:00 PM
Last Post: Windspar

Forum Jump:

User Panel Messages

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