python - 滚动条添加填充 tkinter
问题描述
我试图将滚动条放在 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)
结果如下: 滚动条,额外的填充
我知道无法在我的应用程序中提供所有代码可能会限制可能的答案,但我希望有人至少可以解释为什么简单地将滚动条添加到列表框小部件会影响应用程序其他部分的属性。谢谢!
解决方案
推荐阅读
- python - 基于大序列和异或运算实现问题的最有效方法
- mysql - #2014 - 命令不同步;您现在无法运行此命令 SQL 子查询
- javascript - 如何修改 javascript 文件中的 indexof 以在外部站点加载的文件上使用
- ssl - 在 GKE 的 Istio 入口网关中使用默认 SSL 证书
- php - 在多个 PHP 页面中使用相同的数组
- kubernetes - kubernetes 创建有状态集,pod 未启动
- java - 错误:无法在 Netbeans 中找到或加载主类
- javascript - jQuery 搜索/过滤列表
- javascript - 如何截断浮点数精度以使两个相似的浮点数被视为相同
- r - 如何在R中的列表列表中组合矩阵?