【问题标题】:Tkinter listboxes and canvas won't scroll togetherTkinter 列表框和画布不会一起滚动
【发布时间】:2018-07-31 17:28:05
【问题描述】:

我想要 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

提前感谢您的帮助。

【问题讨论】:

    标签: python canvas tkinter listbox scrollbar


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-05-03
      • 2015-12-18
      • 2014-07-12
      • 2017-07-03
      • 1970-01-01
      • 2013-02-02
      • 2019-11-26
      • 2020-04-27
      • 1970-01-01
      相关资源
      最近更新 更多