功能使我的窗口停止响应。我不知道如何解决这个问题 :/

2024-05-01 21:26:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我的一个功能是介绍我在pygame中制作的一个非常基本的游戏。你知道吗

问题是,我的函数使窗口在执行函数时没有响应,我不知道如何修复它。你知道吗

说到Python和pygame,我是个初学者。你知道吗

这是intro函数的代码:

def intro():
    message_display1("Text A")
    pygame.display.update()
    time.sleep(2)
    gameDisplay.fill(color)
    pygame.display.update()
    time.sleep(2)
    message_display1("Text B")
    pygame.display.update()
    gameDisplay.fill(color)
    pygame.display.update()
    time.sleep(2)
    message_display1("Text C")
    pygame.display.update()
    gameDisplay.fill(color)
    pygame.display.update()

这是message_display1函数:

def message_display1(text):
    largeText = pygame.font.Font('freesansbold.ttf',45)
    TextSurf, TextRect = text_objects(text, largeText)
    TextRect.center = ((display_width/2),(display_height/2))
    gameDisplay.blit(TextSurf, TextRect)
    pygame.display.update()

这是text_objects函数:

def text_objects(text, font):
    textSurface = font.render(text, True, black)
    return textSurface, textSurface.get_rect()

提前谢谢你的帮助。你知道吗


Tags: 函数textmessagetimedefdisplayupdatesleep
1条回答
网友
1楼 · 发布于 2024-05-01 21:26:56

看看我能不能试试这个。你知道吗

首先,我们在try…except子句中尝试一些这种编码,并尽可能使用最通用的异常。 https://docs.python.org/2/tutorial/errors.html

两个添加了一些漂亮的python日志。 https://docs.python.org/2/library/logging.html

现在抛开这两个建议不谈,我认为重要的是要注意您使用的是哪种版本的python,并用您的思维过程的具体布局来完成代码的上下文。让我们面对现实吧,我们不是读心术的人,最好在这里以连贯的方式看到更多的代码。你知道吗

也就是说,在开始用python编程游戏的第一步做得很好,不要放弃。这一切都是关于快速失败和从错误中吸取教训,以便有一天你能成功!你知道吗

谢谢你

-阿贝。你知道吗

相关问题 更多 >