簡體   English   中英

Turtle.ontimer() 等效於 Zelle Graphics (python)?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM