0

我几乎要把我的头发扯掉了:

我正在尝试让 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。谁能看到我做错了什么?我非常渴望得到帮助!

谢谢!

加布

4

1 回答 1

1

xbar 不工作的原因是因为它没有任何东西可以滚动. 将画布配置为大于屏幕的大小后,它开始工作。看看下面的代码,看看我在哪里添加了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()
于 2012-07-07T02:42:42.143 回答