0

I am trying to create a window which consists of frame and a button(s) inside of it.

The problem I am facing is when I set the sizes of the frame, they are no longer valid when the label is added inside of this frame.

Only frame:

from tkinter import *

root = Tk()
root.resizable(False, False)

frame = Frame(root, bg="red", height=200, width=200)
frame.pack(side=LEFT, fill=BOTH)

root.mainloop()

It produces a window with red frame 200x200.

When I add a label inside, then the windows takes size of a label.

from tkinter import *

root = Tk()
root.resizable(False, False)

frame = Frame(root, bg="red", height=200, width=200)
frame.pack(side=LEFT, fill=BOTH)

z = Label(frame, bg="yellow", text='yellow label')
z.pack(side=LEFT, fill=BOTH)

root.mainloop()

How to make a frame with its original size and just add a label inside which will fit properly to the frame sizes?

I can achive this size by adding height and width to the label, but IMO the parent level should determine the size. What if I would like to have more than one label inside of frame - then each label should have sizes applied which is bad, specifing a size in the parent level seems to be more logic.

Thanks

PierekEast
  • 95
  • 1
  • 7
  • Ok, I found an answer here: https://stackoverflow.com/questions/11413459/adding-label-to-frame-in-tkinter-ignores-the-attributes-of-frame – PierekEast Oct 19 '18 at 12:06
  • 1
    Possible duplicate of [Adding label to frame in Tkinter ignores the attributes of frame](https://stackoverflow.com/questions/11413459/adding-label-to-frame-in-tkinter-ignores-the-attributes-of-frame) – Mike - SMT Oct 19 '18 at 12:24

0 Answers0