在tkinter画布上绘图--转载附转链接

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

https://blog.csdn.net/qq_41626607/article/details/89059878

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容