簡體   English   中英

pygame窗口一直沒有響應

[英]pygame window keeps not responding

長時間嘗試安裝2.7的pygame之后,終於安裝好了,現在我已經下載了它,但是現在存在的問題是,在打開幾秒鍾后,它仍然沒有響應。 任何答案將不勝感激,到目前為止我所擁有的代碼僅僅是。

import pygame

pygame.init()

pygame.display.set_mode((640,480))

所以我需要一些幫助。

因此,您想要做的事,就像skrx所說的那樣,是一個while循環,以使代碼連續地保持在while循環和pygame窗口內,並保持for循環,以便能夠關閉窗口。 您可以按照以下方法進行操作:

import pygame
pygame.init()
pygame.display.set_mode((640, 480))  # opens the display

while True:  # the while loop that will keep your display up and running!
    for event in pygame.event.get():  # the for event loop, keeping track of events,
        if event.type == pygame.QUIT:  # and in this case, it will be keeping track of pygame.QUIT, which is the X or the top right
             pygame.quit()  # stops pygame

還有其他方法可以停止while循環,您可以這樣做:

running = True
while running:  # the while loop that will keep your display up and running!
    for event in pygame.event.get():  
        if event.type == pygame.QUIT:
             running = False
pygame.quit()

希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM