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
#2
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
#3
pygame.QUITis an integer and you are trying to call it like a function or method with parentheses after it.
if event.type == pygame.QUIT():
should be...
if event.type == pygame.QUIT:
Reply
#4
1 error. 18 stops because of a problem in 12. Look up info about the pygame quit event.

The logic for the while loop starting in line 10 is also completely wrong. There are two errors cancelling each other out.
Reply
#5
There are no parentheses on QUIT
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  question about my Pygame code Than999 2 1,647 Feb-06-2022, 10:03 PM
Last Post: Than999
  [PyGame] Problems with jump code in pygame Joningstone 4 5,269 Aug-23-2021, 08:23 PM
Last Post: deanhystad
  Distributing Python/Pygame code with CX_Freeze jfng75 2 2,770 Jan-11-2021, 10:23 PM
Last Post: snippsat
Video [PyGame] Space Invaders in PyGame Russ_CW 5 4,903 Nov-22-2020, 12:21 PM
Last Post: Russ_CW
  My Pygame Code always says "(Not responding") noodlespinbot 3 8,000 Feb-29-2020, 10:50 PM
Last Post: Windspar
  [pygame] Improvement with code SheeppOSU 1 2,367 Jul-24-2019, 11:09 AM
Last Post: metulburr
  [PyGame] Beginning PyGame question about "self" jakegold98 2 3,142 Dec-09-2017, 12:51 AM
Last Post: metulburr
  Python Pygame code help Trajme 1 3,954 Dec-07-2017, 04:55 PM
Last Post: nilamo
  Appropriately delay this PyGame code kleynah22 2 4,356 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