[英]Pygame window immediately opens and closes
Originally after I did some searching here, I found a question with the exact same problem I had: Pygame window not responding after a few seconds .最初在这里进行了一些搜索后,我发现了一个与我遇到的问题完全相同的问题: Pygame window not response after a few seconds 。 I reviewed all the answers and tried them, but none of them worked.
我查看了所有答案并尝试了它们,但没有一个起作用。 I tried using for loops to loop through every single event;
我尝试使用 for 循环遍历每个事件;
run = True
while run:
for event in pygame.event.get():
if event == pygame.QUIT()
run = False
But the window still closed.但窗户还是关着。 I also tried:
我也试过:
run = True
while run:
event = pygame.event.get()
if event == pygame.QUIT():
run = False
Which had the same results as the one above.这与上面的结果相同。 Can anyone help?
任何人都可以帮忙吗? Edit: I use PyCharm and MacOS Catalina.
编辑:我使用 PyCharm 和 MacOS Catalina。
pygame.QUIT
is a constante, but pygame.QUIT()
is a call statement. pygame.QUIT
是一个常量,但pygame.QUIT()
是一个调用语句。 Remove the braces.取下大括号。 Anyway, the condition won't work, because you have to compare the
type
attribute of the event to the event type constant (see pygame.event
).无论如何,条件不起作用,因为您必须将事件的
type
属性与事件类型常量进行比较(请参阅pygame.event
)。 Furthermore the :
is missing at the end of the if
-statement.此外,
if
语句末尾缺少:
。
if event == pygame.QUIT()
if event.type == pygame.QUIT:
Furthermore the Indentation is not correct:此外,缩进不正确:
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.