gpt4 book ai didi

Python 主循环和 while 循环

转载 作者:行者123 更新时间:2023-12-01 06:45:19 26 4
gpt4 key购买 nike

我有一个使用 turtle 图形的程序。问题是我有一个游戏循环,但不知道将 mainloop 函数放在哪里。如果我把它放在游戏循环之前,那么游戏循环将不会被执行。如果我把它放在主循环之后将永远不会被执行,因为游戏循环是一个无限循环。最后,如果我将主循环放在游戏循环结束中,那么游戏循环只会执行一次。我应该把主循环放在哪里?

import turtle
#some turtle code
while True:
#some code

turtle.mainloop

最佳答案

If I put it after mainloop will never get executed because the game loop is an infinite loop. Lastly if I put mainloop in game loops end than game loop will only get executed once. Where should I put mainloop?

您应该使用 mainloop() 并使用例如ontimer() 或显式游戏循环。两者都不是。

关于Python 主循环和 while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59248241/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com