0

I'm working with python and TkInter.

I need to place two buttons in a resizable screen that when the screen gets bigger, so do the buttons. I found how to do that in here.

I also found how the weight in grid work in here and got what I wanted:

Two buttons the same size

In theory it works perfect, if I use weight 3 and 1 I should get a column 3 times bigger then the second, if I use 1 and 1 I get 50% each...

My problem is when the text of one button is bigger then the other. I want my buttons to stay with 50% each and it's not what I'm getting:

Two buttons not the same size

My code is:

class MyGUI:

def __init__(self, master):
    self.master = master

    self.btn1 = Button(master, text='X')
    self.btn2 = Button(master, text='XXXXX')

    self.btn1.grid(row=0, column=0, sticky=N+S+E+W)
    self.btn2.grid(row=0, column=1, sticky=N+S+E+W)

    for x in range(2):
        Grid.columnconfigure(master, x, weight=1)

root = Tk()
my_gui = MyGUI(root)
root.mainloop()

So how do I make the buttons stay with 50% each regardless of the text in it?

tvortiz
  • 3
  • 4

1 Answers1

0

You can specify the minsize option in columnconfigure(...) as below:

# get the width of the bigger button
minwidth = max(self.btn1.winfo_reqwidth(), self.btn2.winfo_reqwidth())
for x in range(2):
    Grid.columnconfigure(master, x, weight=1, minsize=minwidth)
acw1668
  • 40,144
  • 5
  • 22
  • 34