问题描述
我试图将滚动条放置在tkinter列表框中,但是每次添加它们时,主窗口顶部都会添加大量空间。
以下是我的应用中的一些摘要。第一个只是生成列表框,从下面的第一个链接图像中可以看到,结果是一个漂亮的刷新窗口。但是,当我从第二个片段添加滚动条时,在窗口顶部会放置大量空间。
#Create a listBox and fill with the data found in a dictionary called "d"
self.datadisplay = ListBox(root,font = ("helvetica,14"))
self.subfields = list(d.keys()) #d is a dictionary that is built elsewhere
for i in range(len(self.subfields)): #iterate through each dictionary item
dataType = type(d[self.subfields[i]])
self.datadisplay.insert(END,str(helpers.displayHandler(self,self.subfields[i],str(dataType)))) #fill the listBox using a helper function called displayHandler that simply formats the data as a string
self.datadisplay.pack(fill = "both",expand = True)
上面的代码很好用,并与我的应用程序中的其余代码一起显示如下所示的窗口: No scrollbars,no extra padding
添加以下几行代码以将滚动条放置在列表框中,导致将大量填充添加到窗口顶部。
scrollbarY = Scrollbar(self.datadisplay,orient=VERTICAL)
scrollbarY.pack(side=RIGHT,fill=Y)
scrollbarX = Scrollbar(self.datadisplay,orient=HORIZONTAL)
scrollbarX.pack(side=BottOM,fill=X)
self.datadisplay.config(xscrollcommand = scrollbarX.set)
scrollbarY.config(command=self.datadisplay.yview)
scrollbarX.config(command=self.datadisplay.xview)
结果如下: Scrollbars,extra padding
我知道无法在我的应用程序中提供所有代码可能会限制可能的答案,但是我希望有人至少可以解释为什么仅将滚动条添加到列表框小部件会影响应用程序其他部分的属性的原因。谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)