Tkinter列表框和画布不会一起滚动

时间:2018-02-21 07:57:44

标签: python canvas tkinter listbox scrollbar

我想在TkInter中使用以下布局: 彼此相邻的4个列表框,旁边的画布,填充按钮(列表框中每个元素都有一个按钮)

问题是,画布可以使用列表框滚动,也可以自己滚动,但是甚至高于它有内容的点,这意味着你可以将它滚动到最顶层,但是属于它的列表框甚至不会移动,它们已经被解除同步。所以问题是,我怎样才能为不能更高的滚动指出一点?

我的代码如下:

from Tkinter import *

def Scroll2Gether(*args):
  list1.yview(*args)
  list2.yview(*args)
  list3.yview(*args)
  list4.yview(*args)
  ButtonLine.yview(*args)

master = Tk()
EndLayer = Canvas(master)
scroll = Scrollbar(orient="vertical", command=Scroll2Gether)
UpperLayer = Frame(EndLayer, bg = '#000fff000')

list1 = Listbox(UpperLayer, bg = "#B2B2B2",width = 60)

list3 = Listbox(UpperLayer, bg = "#B2B2B2",width = 60)

list4 = Listbox(UpperLayer, bg = "#E5E5E5",width = 60)

list2 = Listbox(UpperLayer, bg = "#E5E5E5",width = 60)

Framm = Frame(UpperLayer, bg = "#ffa300", width = 30, )

Address1 = Label(list1, text = "OWNER1", bg= "#E5E5E5",width = 60,font=("Helvetica", 8,"bold"))
Address2 = Label(list2, text = "OWNER2", bg= "#B2B2B2", width = 60,font=("Helvetica", 8,"bold"))
Address3 = Label(list3, text = "MailDL", bg= "#E5E5E5", width = 60,font=("Helvetica", 8,"bold"))
Address4 = Label(list4, text = "ExpirationDate", bg= "#B2B2B2", width = 60,font=("Helvetica", 8, "bold"))

ButtonLine = Canvas(Framm, bg = "#E5E5E5", width = 30)

Address1.pack(side = TOP)
Address2.pack(side = TOP)
Address3.pack(side = TOP)
Address4.pack(side = TOP)

list1.pack(side = LEFT, fill = "y")
list2.pack(side = LEFT, fill = "y")
scroll.pack(side="right",fill="y")
list3.pack(side = LEFT, fill = "y")
list4.pack(side = LEFT, fill = "y")
Framm.pack(side=LEFT)
ButtonLine.pack(side = BOTTOM)

UpperLayer.pack()
EndLayer.pack()

x = 0

photo=PhotoImage(file="email.gif")

for i in ("qwertzuiopasfghjklyxcvbnm"):
 i = Button(text="Mail")
 i.config(image = photo, width = 20, height = 20)
 Button_Window = ButtonLine.create_window(1, 22+x, anchor = NW, window = i)
 x = x+26

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

解决了!我发现将3列分组是没有意义的,所以我创建了一些画布线,并为循环中的每个输入创建了画布。