Python:如何重置海龟图形窗口 [英] Python: How to reset the turtle graphics window

查看:79
本文介绍了Python:如何重置海龟图形窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用乌龟制作带有纸牌的二十一点游戏,每次我玩一只手乌龟时,只打印最后一场比赛而不是清除窗口.是否有一种方法可以在调用时关闭窗口,或者还有其他原因吗?

I am a making a blackjack game with cards using turtle and each time I play a hand turtle just prints over the last game instead of clearing the window. Is there a method that closes the window when it is called or is there another why of doing this?

推荐答案

我想澄清各种海龟函数的作用,因为在这个讨论中存在误解,包括在当前接受的答案中,因为方法名称本身可能会令人困惑:

I want to clarify what various turtle functions do as there are misunderstandings in this discussion, including in the currently accepted answer, as the method names themselves can be confusing:

turtle.mainloop() 又名 turtle.Screen().mainloop() 将控制权交给 tkinter 的事件循环.通常,缺少 turtle.Screen().mainloop()(或 turtle.Screen().exitonclick() 等)会导致窗口刚关闭因为程序将结束,关闭一切.除非脚本是从 Python IDLE -n 中运行的,否则此语句或其变体应该是海龟图形程序中的最后一条语句.

turtle.mainloop() aka turtle.Screen().mainloop() Turns control over to tkinter's event loop. Usually, a lack of turtle.Screen().mainloop() (or turtle.Screen().exitonclick(), etc.) will cause the window to close just because the program will end, closing everything. This, or one of its variants, should be the last statement in a turtle graphics program unless the script is run from within Python IDLE -n.

turtle.done()(不关闭窗口也不重置任何东西.) turtle.mainloop()

turtle.done() (Does not close window nor reset anything.) A synonym for turtle.mainloop()

turtle.clear() 删除这只海龟绘制的所有内容(不仅仅是最后一个).否则不影响乌龟的状态.

turtle.clear() Deletes everything this turtle has drawn (not just the last thing). Otherwise doesn't affect the state of the turtle.

turtle.reset() 执行一个 turtle.clear() 然后重置这个海龟的状态(即方向、位置等.)

turtle.reset() Does a turtle.clear() and then resets this turtle's state (i.e. direction, position, etc.)

turtle.clearscreen() aka turtle.Screen().clear() 删除all 绘图和all 海龟,将窗口重置为其原始状态.

turtle.clearscreen() aka turtle.Screen().clear() Deletes all drawing and all turtles, reseting the window to it's original state.

turtle.resetscreen() 又名 turtle.Screen().reset() 将屏幕上的所有海龟重置为它们的初始状态.

turtle.resetscreen() aka turtle.Screen().reset() Resets all turtles on the screen to their initial state.

turtle.bye() 又名 turtle.Screen().bye() 关闭海龟图形窗口.调用此命令后,我看不到使用任何海龟图形命令的方法.

turtle.bye() aka turtle.Screen().bye() Closes the turtle graphics window. I don't see a way to use any turtle graphics commands after this is invoked.

turtle.exitonclick() aka turtle.Screen().exitonclick() 绑定屏幕点击事件后做一个turtle.Screen().bye() 调用 turtle.Screen().mainloop()

turtle.exitonclick() aka turtle.Screen().exitonclick() After binding the screen click event to do a turtle.Screen().bye() invokes turtle.Screen().mainloop()

不清楚是否可以从海龟内部关闭和重新打开图形窗口,而无需下降到支持海龟(和 Zelle 的 graphics.py)的 tkinter 级别

It's not clear that you can close and reopen the graphics window from within turtle without dropping down to the tkinter level that underpins turtle (and Zelle's graphics.py)

为了在您的二十一点游戏中开始新手,我猜 turtle.reset()turtle.resetscreen() 是您最好的选择.

For purposes of starting a new hand in your blackjack game, I'd guess turtle.reset() or turtle.resetscreen() are your best bet.

这篇关于Python:如何重置海龟图形窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆