turtle.ontimer() equivalent for Zelle Graphics (python)?



是否有一种等效的方法来执行与使用Zelle图形和Python的TURTLE ontimer相同的功能?

ontimer与Zelle一起工作,但它需要打开Turtle窗口(这违背了目的)。我正在想办法利用乌龟。但不需要调用turtle. screen()或任何turtle窗口。或者在zelle graphics.py

中有其他方法

由于GraphWin是tkinterCanvas的子类,我们可以调用Python turtle用来实现ontimer()的相同的Canvas.after()方法:

from graphics import GraphWin, Circle, Rectangle, Point
def change(a, b):
a.undraw()
b.draw(window)
window.after(1000, change, b, a)  # repeat one second later
window = GraphWin("Shape Shifting", 100, 100)
circle = Circle(Point(50, 50), 20)
circle.setFill('red')
circle.draw(window)
square = Rectangle(Point(30, 30), Point(70, 70))
square.setFill('green')
change(circle, square)
window.getMouse()  # Pause to view result
window.close()  # Close window when done

最新更新