0

I want to create a resizable window, and I want all the widgets in there to resize when I resize the window. For this, I'm trying to use grid() and give relative positions to the widgets. This is the code:

c = tk.Canvas(width=400, height=320)
c.grid(row=0, column=0, sticky='w')
Label(root, textvariable=balance_string_var).grid(row=1, column=0, sticky="we")

balance_string_var.set("LABEL")

listbox = Listbox(root, height=30, width=100)
listbox.grid(column=1, row=0, rowspan=2, sticky="e")

I want the Listbox to be aligned to the right (look image). on How can I do it? Thanks

Kristof Rado
  • 713
  • 1
  • 8
  • 19
l000000l
  • 330
  • 1
  • 3
  • 14

2 Answers2

1

Use place instead, .place(relx=0, rely=0.05, relheight=0.03, relwidth=1) !! using 0-1.0 instead of pixels totally scales them properly, it's more flexible than grid

or use pack(side="right")

rn0mandap
  • 333
  • 1
  • 8
1

According to the document for the weight option of columnconfigure():

weight=

A relative weight used to distribute additional space between columns. A column with the weight 2 will grow twice as fast as a column with weight 1. The default is 0, which means that the column will not grow at all.

The listbox widget is put in column 1 of the grid layout of root and column 1 is the last column that contains widget, so calling root.rowconfigure(1, weight=1) will make column 1 to use all the remaining horizontal space.

And so setting sticky='e' in listbox.grid(..., sticky='e') will then put the listbox at the right-most of root window.

acw1668
  • 40,144
  • 5
  • 22
  • 34