首页 > 解决方案 > 为什么调用 root.destroy 仍然不能继续我的循环?

问题描述

我正在创建一个棋盘游戏,并且我正在使用 Tkinter 作为 GUI 界面。我创建了这样的主循环:

while gameOn == True: #The loop
    main_game_AI() #This is the actual game
    root.mainloop() #This puts together the window.
    root.destroy()  #This closes the mainloop so the loop can continue.

但是当我运行它时,循环只迭代了一次。函数的顺序有问题吗?

标签: python-3.xuser-interfacetkinterwhile-loopmain

解决方案


root.mainloop()在根窗口被销毁或调用root.quit(). root.destroy()因此,在用户退出您的程序之前,不会调用 yoru 调用。


推荐阅读