Python Forum

Full Version: question about my pygame code for space shooter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
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()
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:
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.
There are no parentheses on QUIT