我是 Python 新手,并且使用海龟图形在 Python 2.7 中编写了一个简单的程序,该程序绘制了一个分形形状。我遇到的问题是乌龟窗口没有滚动条,所以如果窗口的形状太大,就不可能看到所有的东西。谷歌搜索但没有找到答案。任何人都可以帮忙吗?
问问题
5489 次
2 回答
4
You don't need to call Tkinter functions directly to get scrollbars in turtle
. You just need to call turtle.screensize
and set a screen size that's larger than the display window in at least one of its dimensions. I find it most convenient to open the display window at its default size and let the user resize it, if desired.
Here's a short demo:
import turtle
win_width, win_height, bg_color = 2000, 2000, 'black'
turtle.setup()
turtle.screensize(win_width, win_height, bg_color)
t = turtle.Turtle()
#t.hideturtle()
#t.speed(0)
t.color('white')
for _ in range(4):
t.forward(500)
t.right(90)
turtle.done()
于 2017-01-03T12:47:33.667 回答
3
最后在http://www.python-forum.de/viewtopic.php?f=1&t=24823&start=0找到了一些代码,它为海龟提供了一个滚动的画布:
import turtle
import Tkinter as tkinter
root = tkinter.Tk()
root.geometry('500x500-5+40') #added by me
cv = turtle.ScrolledCanvas(root, width=900, height=900)
cv.pack()
screen = turtle.TurtleScreen(cv)
screen.screensize(2000,1500) #added by me
t = turtle.RawTurtle(screen)
t.hideturtle()
t.circle(100)
root.mainloop()
于 2013-02-14T23:02:15.617 回答