I've read it over and over again, but I can't help but get an error even though they're all the same programs.
import pygame aspg,sys
pg.init()
screen=pg.display.set_mode(800,600))
while True:
screen.fill(pg.Color("WHITE"))
pg.draw.rect(screen, pg.Color("RED"), (100, 100, 150))
pg.display.update()
for event inputg.event.get():
if event.type==pg.QUIT:
pg.quit()
sys.exit()
The pg part of pg.display.update() turns red and says SyntaxError.
I am using an IDLE for Python 3.6
Write down all the error messages in the question without abbreviating them.
Or, it may look like a question on the editor screen, but if I try it, won't it appear like this?(However, the path name is the file name in the environment I tried.)
File "C:\Develop\Python\pg.py", line 8
pg.display.update()
^
SyntaxError: invalid non-printable character U+3000
If the source code is still copied instead of being mixed up in the question article, the indentation of the line is not 4 half-width blank but 2 full-width blank.
Correct it to 4 half-width spaces and it will work.
"By the way, there is ""Check Module"" on the ""Run"" menu on the Python-IDLE editor screen, which you can check if you run it, but in Python 3.8 the pg
part is red (or pink?) and the message box is displayed under the ""Syntax Error"" title."
If this is Python 3.9 or 3.10, the full-width blank at the beginning of the line will be pink, and the sentence part will be changed to invalid non-printable character U+3000 as shown above.
Perhaps the number of Python versions used in the reference book is 3.6, so I think I combined the number of Python versions used, but if the minor version (the number immediately after 3.) is different, both should be installed, so you should consider including the latest version (3.10).
Additional Note:
After checking the IDLE above, I suddenly thought about it and tried Python 3.8 and found that the error message changed as shown in IDLE.This is the actual situation of the question.
I understand that the check content varies depending on the number of Python versions.The new version of the message is closer to the cause of the problem.
File "C:\Develop\Python\pg.py", line 8
pg.display.update()
^
SyntaxError: invalid character identifier
© 2024 OneMinuteCode. All rights reserved.