0

I'm trying to place two Text widgets side by side with 3:1 width proportions using the grid layout:

root = tk.Tk()

t1 = tk.Text(root)
t2 = tk.Text(root)

t1.grid(row=0, column=0, sticky=tk.E+tk.W)
t2.grid(row=0, column=1, sticky=tk.E+tk.W)

root.grid_columnconfigure(0, weight=3)
root.grid_columnconfigure(1, weight=1)

root.mainloop()

After starting the application the width of the widgets seem 1:1. Shrinking the window, makes the first widget (t1) narrower. The weight values suggest, that the opposite should happen (t2 getting narrower until reaching 75:25). Instead of that, t1 gets really narrow, while t2 uses most of the available space. Example resize

What am I doing wrong?

newb88
  • 15
  • 5

1 Answers1

0

Weight only affects how grid allocates extra space. You're requesting both widgets to start out the same size, and you are letting the text widgets control the size of the UI so there will be no extra space. Therefore, the weight has no affect on the initial layout.

In addition to setting the weight, you need the widgets to start out in the ratio that you want:

t1 = tk.Text(root, width=45)
t2 = tk.Text(root, width=15)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685