Expanding Button Widget to fill the entire frame in Tkinter

I have 4 buttons in my Left Frame I would like them to resize whenever I resize

my window but it doesn't work buttons are not expanding as i expand my window

Below is my code for it

from tkinter import * 
root = Tk()
leftFrame = Frame(root)
leftFrame.pack(side=LEFT)
rightFrame = Frame(root)
rightFrame.pack(side=RIGHT)

button1 = Button(leftFrame,text="Round 1",fg="white",bg="black")
button2 = Button(leftFrame,text="Round 2",fg="yellow",bg="blue")
button3 = Button(leftFrame,text="Round 3",fg="purple",bg="cyan")
button4 = Button(leftFrame,text="Round 4",fg="green",bg="orange")

button1.pack(expand=True,fill='both')
button2.pack(expand=True,fill='both')
button3.pack(expand=True,fill='both')
button4.pack(expand=True,fill='both')

root.mainloop()

Help is appreciated

I am using Python 3.5 and Editor is Pycharm

1 answer

  • answered 2018-05-16 07:31 fhdrsdg

    Actually, your buttons are filling the entire frame. The problem is that the frames aren't filling the root window. This is because you pack the frames without specifying that they should grow to fill their parent.

    pack your frames like this:

    leftFrame = Frame(root)
    leftFrame.pack(side=LEFT, expand=True, fill='both')
    rightFrame = Frame(root)
    rightFrame.pack(side=RIGHT, expand=True, fill='both')