2013-02-06 136 views
4

我是新來的Python,並且已經用Python 2.7寫了一個簡單的程序,它使用龜圖形繪製分形。我遇到的問題是烏龜窗口沒有滾動條,所以如果窗口的形狀太大,就不可能看到全部。已使用Google搜索,但沒有找到答案。誰能幫忙?Python龜窗口滾動條

+0

它[似乎是可能的(http://docs.python.org/2/library/turtle.html#turtle.ScrolledCanvas)添加滾動條,但它需要一些Tkinter的知識。 – Kevin

回答

2

終於發現在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() 
2

你並不需要直接調用Tkinter的函數來獲取滾動條在turtle。您只需撥打turtle.screensize並在其至少一個維度上設置比顯示窗口大的屏幕大小。如果需要,我發現最方便的方法是以默認大小打開顯示窗口並讓用戶調整大小。

這裏有一個簡短的演示:

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()