[英]turtle.ontimer() equivalent for Zelle Graphics (python)?
是否有一种等效的方法可以使用 Zelle Graphics 和 Python 执行与 TURTLE 准时器相同的功能?
ontimer 与 Zelle 一起工作,但它需要打开 Turtle 窗口(这违背了目的)。 我试图找出一种使用turtle.ontimer 的方法,但不必调用turtle.Screen() 或任何turtle 窗口。 或者如果在 zelle graphics.py 中有另一种方法可以做到这一点
由于GraphWin
是 tkinter Canvas
的子类,我们可以调用 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.