Python画布不能自动扩展为龟打印
我有一个关于L-系统的项目。我试图添加一张打印L系统的乌龟;但是,与文本字段不同,画布不会展开。当我打印更多文本时,我的文本字段使用滚动条进行扩展。然而,乌龟卡在画布上。我很困难。Python画布不能自动扩展为龟打印
frame2 = tki.Frame(frame, bg='yellow', width=810, height=510) frame2.pack()
frame2.place(x=500,y=5)
cv = Canvas(frame2, width=2000, height=2000)
cv.place(x=0, y=0)
screen = turtle.TurtleScreen(cv)
t = turtle.RawTurtle(screen)
hbar=Scrollbar(frame2,orient=HORIZONTAL)
hbar.pack(side=BOTTOM,fill=X)
hbar.config(command=cv.xview)
vbar=Scrollbar(frame2,orient=VERTICAL)
vbar.pack(side=RIGHT,fill=Y)
vbar.config(command=cv.yview)
cv.config(width=800,height=500)
cv.config(xscrollcommand=hbar.set, yscrollcommand=vbar.set)
cv.pack(side=LEFT,expand=True,fill=BOTH)
回答:
如果我正确理解你的问题,为什么不乌龟库提供了对您为此工作ScrolledCavas
:
编辑:我已经在帧大小开始画布大小和加入ScrolledCanvas
的reset()
方法来扩大动态画布:
import tkinter as tk from turtle import TurtleScreen, RawTurtle, ScrolledCanvas
size = 100
canvsize = 300
root = tk.Tk()
root.geometry('600x500')
frame = tk.Frame(root, width=300, height=300)
frame.pack()
frame.place(x=50, y=50)
canvas = ScrolledCanvas(frame, canvwidth=canvsize, canvheight=canvsize)
canvas.pack(side=tk.LEFT)
screen = TurtleScreen(canvas)
screen.bgcolor('yellow')
turtle = RawTurtle(screen, visible=False)
turtle.dot(size, "green")
def expand():
global canvsize, size
if size < 800:
size += 10
if size > canvsize:
canvsize += 100
canvas.reset(canvwidth=canvsize, canvheight=canvsize)
turtle.dot(size, "green")
screen.ontimer(expand, 100)
screen.ontimer(expand, 100)
screen.mainloop()
以上是 Python画布不能自动扩展为龟打印 的全部内容, 来源链接: utcz.com/qa/260611.html