Tkinter列表框和画布不会一起滚动
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Tkinter列表框和画布不会一起滚动相关的知识,希望对你有一定的参考价值。
我希望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
在此先感谢您的帮助。
答案
解决了!我发现将3列分组是没有意义的,所以我创建了一些画布线,并为循环中的每个输入创建了画布。
以上是关于Tkinter列表框和画布不会一起滚动的主要内容,如果未能解决你的问题,请参考以下文章