带有两个相邻文本框的选项卡上缺少垂直滚动条
Missing a vertical scrollbar on a tab with two adjacent textboxs
我尝试在一个选项卡中添加两个文本框,每个文本框都有自己的滚动条。
使用一个文本框可以正确显示滚动条。但是,当我添加另一个文本框时,第一个文本框上的垂直滚动条消失了。我尝试更改一些网格位置但没有成功。
结果照片如下:
这是我的代码:
self.txtputthrough = tk.Text(self.tab2, height=25)
self.txtputthrough.grid(row=0, column=0, sticky="ns")
self.vsb4 = ttk.Scrollbar(self.tab2, command=self.txtputthrough.yview, orient="vertical")
self.vsb4.grid(row=0, column=1, sticky="ns")
self.hsb4 = ttk.Scrollbar(self.tab2, command=self.txtputthrough.xview, orient="horizontal")
self.hsb4.grid(row=1, column=0, columnspan=1, sticky="ew")
self.txtputthrough.configure(yscrollcommand=self.vsb4.set, xscrollcommand=self.hsb4.set)
self.txtputthrough2 = tk.Text(self.tab2, height=25)
self.txtputthrough2.grid(row=0, column=2, sticky="nsew")
self.vsb5 = ttk.Scrollbar(self.tab2, command=self.txtputthrough2.yview, orient="vertical")
self.vsb5.grid(row=0, column=4, sticky="ns") # if here is column number < 4 then no vertical scrollbar shown
self.hsb5 = ttk.Scrollbar(self.tab2, command=self.txtputthrough2.xview, orient="horizontal")
self.hsb5.grid(row=1, column=2, columnspan=1, sticky="ew")
self.txtputthrough2.configure(yscrollcommand=self.vsb5.set, xscrollcommand=self.hsb5.set)
由于文本框的默认宽度大小为 50。
网格将文本框的左侧放在正确的位置,但无法显示文本框的右侧,因为它扩展了 window 大小(制表符)
然后我的解决方案是创建两个框架并将每个文本框放在一个框架中,并让文本框根据框架自动调整大小。
这是我的代码:
# Create frames
self.frame1tab2=ttk.Frame(self.tab2)
self.frame1tab2.grid(row=0, column=0, sticky='nsew')
self.frame1tab2.rowconfigure(0, weight=1) # this will let frame auto resizes following the tab windows
self.frame1tab2.columnconfigure(0, weight=1)
self.frame1tab2.grid_propagate(True)
self.frame2tab2=ttk.Frame(self.tab2)
self.frame2tab2.grid(row=0, column=1, sticky='nsew')
self.frame2tab2.rowconfigure(0, weight=1)
self.frame2tab2.columnconfigure(0, weight=1)
self.frame2tab2.grid_propagate(True)
# Put textboxes into frames
self.txtputthrough = tk.Text(self.frame1tab2)
self.txtputthrough.grid(row=0, column=0, sticky="nsew") # this will let textbox auto resizes following the frame
self.vsb6 = ttk.Scrollbar(self.frame1tab2, command=self.txtputthrough.yview, orient="vertical")
self.vsb6.grid(row=0, column=1, sticky="wns")
self.hsb6 = ttk.Scrollbar(self.frame1tab2, command=self.txtputthrough.xview, orient="horizontal")
self.hsb6.grid(row=1, column=0, columnspan=1, sticky="ew")
self.txtputthrough.configure(yscrollcommand=self.vsb6.set, xscrollcommand=self.hsb6.set)
self.txtputthrough2 = tk.Text(self.frame2tab2, height=25)
self.txtputthrough2.grid(row=0, column=0, sticky="nsew")
self.vsb5 = ttk.Scrollbar(self.frame1tab2, command=self.txtputthrough.yview, orient="vertical")
self.vsb5.grid(row=0, column=1, sticky="wns")
self.hsb5 = ttk.Scrollbar(self.frame1tab2, command=self.txtputthrough.xview, orient="horizontal")
self.hsb5.grid(row=1, column=0, columnspan=1, sticky="ew")
self.txtputthrough.configure(yscrollcommand=self.vsb5.set, xscrollcommand=self.hsb5.set)
我尝试在一个选项卡中添加两个文本框,每个文本框都有自己的滚动条。
使用一个文本框可以正确显示滚动条。但是,当我添加另一个文本框时,第一个文本框上的垂直滚动条消失了。我尝试更改一些网格位置但没有成功。
结果照片如下:
这是我的代码:
self.txtputthrough = tk.Text(self.tab2, height=25)
self.txtputthrough.grid(row=0, column=0, sticky="ns")
self.vsb4 = ttk.Scrollbar(self.tab2, command=self.txtputthrough.yview, orient="vertical")
self.vsb4.grid(row=0, column=1, sticky="ns")
self.hsb4 = ttk.Scrollbar(self.tab2, command=self.txtputthrough.xview, orient="horizontal")
self.hsb4.grid(row=1, column=0, columnspan=1, sticky="ew")
self.txtputthrough.configure(yscrollcommand=self.vsb4.set, xscrollcommand=self.hsb4.set)
self.txtputthrough2 = tk.Text(self.tab2, height=25)
self.txtputthrough2.grid(row=0, column=2, sticky="nsew")
self.vsb5 = ttk.Scrollbar(self.tab2, command=self.txtputthrough2.yview, orient="vertical")
self.vsb5.grid(row=0, column=4, sticky="ns") # if here is column number < 4 then no vertical scrollbar shown
self.hsb5 = ttk.Scrollbar(self.tab2, command=self.txtputthrough2.xview, orient="horizontal")
self.hsb5.grid(row=1, column=2, columnspan=1, sticky="ew")
self.txtputthrough2.configure(yscrollcommand=self.vsb5.set, xscrollcommand=self.hsb5.set)
由于文本框的默认宽度大小为 50。 网格将文本框的左侧放在正确的位置,但无法显示文本框的右侧,因为它扩展了 window 大小(制表符)
然后我的解决方案是创建两个框架并将每个文本框放在一个框架中,并让文本框根据框架自动调整大小。
这是我的代码:
# Create frames
self.frame1tab2=ttk.Frame(self.tab2)
self.frame1tab2.grid(row=0, column=0, sticky='nsew')
self.frame1tab2.rowconfigure(0, weight=1) # this will let frame auto resizes following the tab windows
self.frame1tab2.columnconfigure(0, weight=1)
self.frame1tab2.grid_propagate(True)
self.frame2tab2=ttk.Frame(self.tab2)
self.frame2tab2.grid(row=0, column=1, sticky='nsew')
self.frame2tab2.rowconfigure(0, weight=1)
self.frame2tab2.columnconfigure(0, weight=1)
self.frame2tab2.grid_propagate(True)
# Put textboxes into frames
self.txtputthrough = tk.Text(self.frame1tab2)
self.txtputthrough.grid(row=0, column=0, sticky="nsew") # this will let textbox auto resizes following the frame
self.vsb6 = ttk.Scrollbar(self.frame1tab2, command=self.txtputthrough.yview, orient="vertical")
self.vsb6.grid(row=0, column=1, sticky="wns")
self.hsb6 = ttk.Scrollbar(self.frame1tab2, command=self.txtputthrough.xview, orient="horizontal")
self.hsb6.grid(row=1, column=0, columnspan=1, sticky="ew")
self.txtputthrough.configure(yscrollcommand=self.vsb6.set, xscrollcommand=self.hsb6.set)
self.txtputthrough2 = tk.Text(self.frame2tab2, height=25)
self.txtputthrough2.grid(row=0, column=0, sticky="nsew")
self.vsb5 = ttk.Scrollbar(self.frame1tab2, command=self.txtputthrough.yview, orient="vertical")
self.vsb5.grid(row=0, column=1, sticky="wns")
self.hsb5 = ttk.Scrollbar(self.frame1tab2, command=self.txtputthrough.xview, orient="horizontal")
self.hsb5.grid(row=1, column=0, columnspan=1, sticky="ew")
self.txtputthrough.configure(yscrollcommand=self.vsb5.set, xscrollcommand=self.hsb5.set)