Tkinter网格传播和滚动条

时间:2018-08-24 10:16:40

标签: python-3.x tkinter grid

我有一个文本小部件,我希望将其设置为特定大小(以像素为单位)。为此,我将其和滚动条放在grid_propate设置为False的框架中,如下所示:

with open (file_name) as f: c = f.read ()
self.holder = Frame (self.main_frame)
self.holder.grid (row = 0, column = 0, sticky = "nsew")
self.holder.grid_propagate (False)
self.holder.grid_columnconfigure (0, weight = 1)
self.holder.grid_rowconfigure (0, weight = 1)
self.text = Text (self.holder)
self.text.grid (row = 0, column = 0, sticky = "nsew")
self.text.insert ("end", c)
self.scroll = Scrollbar (self.holder, orient = "vertical", command = self.text.yview)
self.scroll.grid (row = 0, column = 1, sticky = "ns")
self.text.config (yscrollcommand = self.scroll.set)

但是,在将grid_propagate设置为False时,滚动条的行为却很奇怪(在顶部时,它不显示可滚动性-如果存在这样的单词-然后再向下滚动,则表明您可以滚动难以形容,因此很难描述,因此请在尝试之前先尝试代码)。将其设置为True,一切正常。如何解决?

非常感谢。

0 个答案:

没有答案