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()
我搜索了这个问题并且通常回答说应该调用pygame.event.get()来与OS进行交互。 但是,即使在循环中调用了pygame.event.get(),它也会停止并突然没有响应弹出。关闭按钮也不起作用。
(我使用了线程,因为我想从主文件中分离GUI处理程序)
答案 0 :(得分:1)