Search code examples
pythonpython-3.xtkinterframepython-3.4

python 3.4 tkinter frame does not fill in vertical direction


I am making a tkinter application to view a plot. I want the window to be maximized on startup, which works. I also want to make a frame in which I would place the plot and its information. When I pack the frame and try to make it fill both horizontal and vertical, it goes wrong. It does fill horizontal, but it does not fill vertical. Searching for answers here only gives me frames with scrollbars.

This is the code that I use.

from tkinter import *
from tkinter.filedialog import askopenfilename
import tkinter.messagebox as messagebox
import datetime, os

root = Tk()

tl = root.winfo_toplevel()
tl.wm_state('zoomed')

mainframe = Frame(root, bd=1, relief=RAISED, cursor="dotbox")
mainframe.pack(side=TOP, fill=BOTH)    # It only fills horizontal

root.mainloop()

Why does it only fill horizontal and not vertical?


Solution

  • You need to pass expand option with value larger than 0 to tell pack geometry manager to assign additinoal space for the widget.

    mainframe.pack(side=TOP, fill=BOTH, expand=1)
    

    Otherwise, the widget will not be expanded.