Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntaxt error part 2
#1
Hello, I have followed the steps laid out and I want to thank you for bringing me closer to a solution in writing the game code Idel.

However even after applying all the changes I still get syntax errors.

I have placed a screenshot of the code in the attachments as I have still not figured out how to use BBcode.

My question is, can anyone see what else has gone wrong and should I use an Idel alternative for pygame?

Thank you everyone for your patience with guy that is a boomer with technology.

Cheers.
deanhystad write Jun-12-2023, 06:20 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

Thumbnail(s)
   
Reply
#2
Post code as text, not screen shots. Consider using BBTags as the price of admission for getting any help on this forum. All you need to do is press the yellow/blue Python button in the post editor, then paste the code between the python tags that appear. Use the red circle with an X to add tags for posting error messages.

Your post does not show a pygame import of pygame.init(). pygame.init() must be the first pygame function in your program (must be before pygame.display.set_mode().
import pygame

WIDTH, HEIGHT = 100, 100
pygame.init()
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
You should test if __name__ == "__main__", not "_main_" (double underscore, not single). Not that it matters. Your main() will never run because your indenting is still messed up.

I don't see any syntax errors in your program. What is the error when you try to run your program? Please post the error text, with tags. My guess is you are seeing this:
Error:
SyntaxError: multiple statements found while compiling a single statement
That is the error I get if I paste a program into the IDLE Shell. The Shell is not the tool you use for writing Python programs. Use the "File" menu to create a new file. Type your code in the editor window. Save the file. Use the "Run" menu to run your new program.
Reply
#3
You just posted this in your original post. Since you are still attacking the same problem.
Are you just typing this in to idle ?

Show error. It tells you where to look.
You still need double underscore in '__main__' .
You need to indent code correctly.
import pygame

WIDTH, HEIGHT  = 900, 500
# Screen, surface, or window should not be capitalize.
window = pygame.display.set_mode((WIDTH, HEIGHT))

def main():
    run = True
    while run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
            
            window.fill('black')
            pygame.display.flip()

# Use for testing. Can not be in loop.
if __name__ == '__main__':
    main()
99 percent of computer problems exists between chair and keyboard.
Reply


Forum Jump:

User Panel Messages

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