5
from tkinter import *

root = Tk()
root.title('My app')
root.minsize(250, 100)
label1 = Label(root, text = 'Hello world!', fg = 'red', bg = 'yellow',
               font = 'Monaco')
label1.pack(fill = X)
label2 = Label(root, text = 'Some more text!', fg = 'green', bg = 'cyan',
               font = 'Arial')
label2.pack(fill = Y)
root.mainloop()

When I run the code, label1 stretches perfectly along the X axis while label2 doesn't stretch at all along the Y axis. What am I missing?

Result

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

5

It is filling the space allocated for it. Tkinter will try to allocate the smallest amount of space necessary for the widget.

If you want tkinter to expand the widget to fill all remaining space, you need to set the expand attribute to True.

label2.pack(fill = Y, expand=True)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685