import turtle
from tkinter import *
def drawp():
theScreen = turtle.TurtleScreen(canva)
path = turtle.RawTurtle(theScreen)
path.forward(100)
path.right(90)
path.forward(150)
theScreen.mainloop()
root = Tk()
root.title("the path")
canva = Canvas(root, width=400, height=400)
canva.pack()
aa = Button(root, text="Draw", command=drawp)
aa.pack()
root.mainloop()
总结
相对于经常用到的 turtle 独立绘图,关键在于下面两条语句的区别:
独立绘图
theScreen = turtle.Screen()
path = turtle.Turtle()
在tkinter画布上绘图
theScreen = turtle.TurtleScreen(canva)
path = turtle.RawTurtle(theScreen)
path = turtle.RawTurtle(canva) #参数换成canva也可以
————————————————
版权声明:本文为CSDN博主「学了别忘」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_41626607/article/details/89059878