I've created two Text box widgets side-by-side. The left Text box contains 100 rows of Checkbutton boxes. The right Text box contains 100 rows of text. I've configured both Text boxes to have the same height of 30 and width of 10.
When I run the program, the left Text box grows vertically beyond the size of my view able screen area. As a result, the right Text box is pushed so far down the Frame that I can no longer see it. I know it's there, because when I reduce the number of rows (for both boxes) to 50 (as opposed to 100), I can see the right Text box.
Also, I noticed that the left Scrollbar isn't connected to the left Text box. However, the right Scrollbar is correctly connected to the right Text box.
Could you please help me understand:
1) Why does the left Text box grow vertically (outside the defined Text widget size) and out of sync with the right Text box size and position?
2) Why doesn't the left Scrollbar attach to the left Text widget (like the right Text box)?
Here is my code so far:
#!/usr/bin/python
from Tkinter import *
class MyApp:
def __init__(self, parent):
self.myParent = parent
self.main_container = Frame(self.myParent)
self.main_container.grid(row=0, column=0, columnspan=4)
self.left_frame = Frame(self.main_container)
self.left_frame.grid(row=0, column=0, columnspan=2)
self.right_frame = Frame(self.main_container)
self.right_frame.grid(row=0, column=2, columnspan=2)
self.checkbox_scrollbar = Scrollbar(self.left_frame)
self.checkbox_scrollbar.grid(row=0, column=1, sticky='NS')
self.checkbox_text = Text(self.left_frame, height=30, width=10, yscrollcommand=self.checkbox_scrollbar.set)
self.checkbox_text.grid(row=0, column=0)
self.checkbox_scrollbar.config(command=self.checkbox_text.yview)
self.databox_scrollbar = Scrollbar(self.right_frame)
self.databox_scrollbar.grid(row=0, column=1, sticky='NS')
self.databox_text = Text(self.right_frame, height=30, width=10, yscrollcommand=self.databox_scrollbar.set)
self.databox_text.grid(row=0, column=0)
self.databox_scrollbar.config(command=self.databox_text.yview)
my_dict = {}
for each_num in range(100):
my_line = "Line number: " + str(each_num)
my_dict[my_line] = 0
for my_key in my_dict:
my_dict[my_key] = IntVar()
cb = Checkbutton(self.checkbox_text, text=my_key, variable=my_dict[my_key])
cb.grid(sticky='W')
for each_entry in range(100):
entry_line = "This is entry number: " + str(each_entry) + "\n"
self.databox_text.insert(END, entry_line)
root = Tk()
root.title("Checkbox UI Test")
myapp = MyApp(root)
root.mainloop()