Python 如何在不冻结的情况下在角落中使用[x]关闭窗口?
我想单击窗口角落的[x],让它关闭整个应用程序。相反,它正在冻结,没有反应。谢谢你的帮助Python 如何在不冻结的情况下在角落中使用[x]关闭窗口?,python,pygame,Python,Pygame,我想单击窗口角落的[x],让它关闭整个应用程序。相反,它正在冻结,没有反应。谢谢你的帮助 import sys #import and init pygame import pygame pygame.init() #create the screen window = pygame.display.set_mode((640, 480)) #draw a line - see http://www.pygame.org/docs/ref/draw.html for more pyga
import sys
#import and init pygame
import pygame
pygame.init()
#create the screen
window = pygame.display.set_mode((640, 480))
#draw a line - see http://www.pygame.org/docs/ref/draw.html for more
pygame.draw.line(window, (255, 255, 255), (0, 0), (30, 50))
#draw it to the screen
pygame.display.flip()
#input handling (somewhat boilerplate code):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
else:
print event
我已经习惯java,所以想知道是否有一个dispose and close类型的框架操作。尝试在
sys.exit(0)
之前添加一个pygame.quit()
关闭pygame窗口,如下所示:
import sys
import pygame
pygame.init()
window = pygame.display.set_mode((640, 480))
pygame.draw.line(window, (255, 255, 255), (0, 0), (30, 50))
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit(0)
else:
print event
尝试在
sys.exit(0)
之前添加一个pygame.quit()
,关闭pygame窗口,如下所示:
import sys
import pygame
pygame.init()
window = pygame.display.set_mode((640, 480))
pygame.draw.line(window, (255, 255, 255), (0, 0), (30, 50))
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit(0)
else:
print event
或者,如果
为True时:
为未完成时:
并且在退出时设置done=True
它将很好地退出。或者,如果为True时:
为未完成时:
并且在退出时设置done=True时,它将很好地退出。