2012-07-05 55 views
0

我已經到了撕扯我的頭髮了點這一個:Python的Tkinter的xscrollbar不工作

我試圖得到一個xscrollbar和yscrollbar工作,這樣我可以在周圍Tkinter的大畫布上移動。我很沮喪的原因是因爲yscrollbar似乎正在使用正確的相同代碼(到處用y代替x)。這裏是我有什麼:

master = Tk() 
scrolly = Scrollbar(master,orient = VERTICAL) 
scrollx = Scrollbar(master,orient = HORIZONTAL) 
scrollx.pack(side = TOP,fill = X) 
scrolly.pack(side = RIGHT,fill = Y) 
w = Canvas(master, width=1000,height=1000,yscrollcommand = scrolly.set,xscrollcommand = scrollx.set,scrollregion=(0,0,1000,1000)) 
s = Scale(master,from_= 0, to=len(worldlist)-1,orient = HORIZONTAL,length = 595) 
s.pack(side = BOTTOM) 
w.pack() 
setSys(worldlist[0],master,w) 
def show(self): 
    w.delete(ALL) 
    setSys(worldlist[s.get()],master,w) 
s.config(command = show) 
scrolly.config(command = w.yview) 
scrollx.config(command = w.xview) 
mainloop() 

我想要畫布和坐在底部的比例小部件。在右側和頂部分別是ybar和xbar。任何人都可以看到我做錯了什麼?我非常渴望得到一些幫助!

謝謝!

加布

+0

當你說它不起作用,這是否意味着它出現,但拖動它沒有效果? –

+0

圍繞滾動條的欄在頂部水平顯示,但其中沒有滾動條。 – user1503132

+0

@BryanOakley看起來像灰色的酒吧,在嘗試了他發佈的代碼後 – TankorSmash

回答

1

X條不工作的原因是因爲它有什麼可滾動。將畫布配置爲比屏幕大的尺寸後,它開始工作。看看下面的代碼,看看我在哪裏添加了scrollregion配置。 http://www.java2s.com/Code/Python/GUI-Tk/ScrolledCanvas.htm

from Tkinter import * 

def show(self): 
    w.delete(ALL) 
    setSys(worldlist[s.get()],master,w) 

master = Tk() 

scrolly = Scrollbar(master,orient = VERTICAL) 
scrollx = Scrollbar(master,orient = HORIZONTAL) 
scrollx.pack(side = TOP,fill = X) 
scrolly.pack(side = RIGHT,fill = Y) 

w = Canvas(master, width=500, height=500, yscrollcommand = scrolly.set, 
      xscrollcommand = scrollx.set, scrollregion=(0,0,1000,1000)) 
w.config(scrollregion=(0, 0, 500, 5000)) 
w.pack() 

s = Scale(master,from_= 0, to=100-1,orient = HORIZONTAL,length = 595) 
s.pack(side = BOTTOM) 
s.config(command = show) 


scrolly.config(command = w.yview) 
scrollx.config(command = w.xview) 


mainloop()