Python pygame没有响应(pygame.event.get()已被调用)
我搜索了这个问题,通常的答案是,应该调用pygame.event.get()来与操作系统进行交互。 但是,即使在循环中调用了pygame.event.get(),它也会停止并突然弹出没有响应的窗口。“关闭”按钮也不起作用Python pygame没有响应(pygame.event.get()已被调用),python,pygame,Python,Pygame,我搜索了这个问题,通常的答案是,应该调用pygame.event.get()来与操作系统进行交互。 但是,即使在循环中调用了pygame.event.get(),它也会停止并突然弹出没有响应的窗口。“关闭”按钮也不起作用 (我使用线程是因为我想将GUI处理程序与主文件分离)在许多地方,您可以找到从主线程调用事件处理的建议 甚至文件也说: 应该从主线程调用事件子系统。如果你愿意 要将事件从其他线程发布到队列中,请使用 fastevent包 不要把这个和其他东西混在一起 import pygame
(我使用线程是因为我想将GUI处理程序与主文件分离)在许多地方,您可以找到从主线程调用事件处理的建议 甚至文件也说: 应该从主线程调用事件子系统。如果你愿意 要将事件从其他线程发布到队列中,请使用 fastevent包 不要把这个和其他东西混在一起
import pygame
import color
def renderText(msg, topleft, font_type, font_size, color):
font = pygame.font.SysFont(font_type, font_size)
text = font.render(msg, True, color)
screen.blit(text, topleft)
def updateScreen(scr, clock):
global screen
screen = scr
screenType = "main" # default main screen
size = 25
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit(0)
if screenType == "main":
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
size+=1
mainScreen(size)
pygame.display.update()
clock.tick(30)
def mainScreen(size):
screen.fill(color.GREEN) # color.GREEN = (0, 255, 0)
renderText("Single mode", (120, 120), 'comicsansms', size, color.RED) # color.RED = (255, 0, 0)
if __name__ == "__main__":
pygame.init()
screen = pygame.display.set_mode((676, 459))
pygame.display.set_caption('MATGO')
clock = pygame.time.Clock()
main = threading.Thread(target = updateScreen, args = (screen, clock))
main.start()