Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 手动配置滚动条';s Y尺寸_Python_Python 3.x_Tkinter - Fatal编程技术网

Python 手动配置滚动条';s Y尺寸

Python 手动配置滚动条';s Y尺寸,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,让我介绍一下我想做什么 我正在创建一个简单的Tkinter程序,它使用Treeview小部件为用户显示信息 起初我使用的是.grid(),但现在我觉得使用.place()更舒服。这里的问题是滚动条。与.pack()一样 相反 作为奖励,当我使用.pack()时 这是代码,如果您需要: self.ah = Treeview(self.M, selectmode='browse') self.ah["columns"] = ("id", "time", "pr") # self.ah.heading

让我介绍一下我想做什么

我正在创建一个简单的Tkinter程序,它使用Treeview小部件为用户显示信息

起初我使用的是.grid(),但现在我觉得使用.place()更舒服。这里的问题是滚动条。与.pack()一样

相反

作为奖励,当我使用.pack()时

这是代码,如果您需要:

self.ah = Treeview(self.M, selectmode='browse')
self.ah["columns"] = ("id", "time", "pr")
#
self.ah.heading('#0', text='Description', anchor='c')
self.ah.column('#0', anchor='c', width=170)
#
self.ah.heading('id', text='ID', anchor='c')
self.ah.column('id', anchor='c', width=30)
#
self.ah.heading('time', text='time', anchor='c')
self.ah.column('time', anchor='c', width=100)
#
self.ah.heading('pr', text='stuff', anchor='c')
self.ah.column('pr', anchor='c', width=70)
#
self.ah.place(x=400, y=70)
#
self.ah.scroll = Scrollbar(self.M, orient='vertical', command=self.ah.yview)
#
self.ah.scroll.place(x=770, y=70)
self.ah.config(yscrollcommand=self.ah.scroll.set)
谢谢大家!!
此外,如有任何暗示,我们将不胜感激。:)

将Treeview和滚动条打包到一个框架中,然后使用place将框架定位到需要的位置。像这样:

self.ah_frame = Frame(self.M)
self.ah = Treeview(self.ah_frame, selectmode='browse')
self.ah.pack(side=LEFT)
self.ah.scroll = Scrollbar(self.ah_frame, orient='vertical', command=self.ah.yview)
self.ah.scroll.pack(side=RIGHT, fill=Y, expand=True)

self.ah_frame.place(x=400, y=70) # place the Frame that contains both the Treeview and Scrollbar

另外,我强烈建议您尽可能避免放置
place
。小部件随用户设置、字体和操作系统的不同而改变大小。使用place意味着您的代码在您的计算机上的外观与您希望的相同,但在其他计算机上则不同。

您能为您的问题创建一个解决方案吗?这将使您更有可能获得高质量的帮助。我会在以后的问题中考虑到这一点,谢谢!很抱歉给您带来不便,谢谢!它工作得很好!我正在制作的程序将只在这台计算机上使用,但我以后将避免使用
place