Kootling Kootling - 1 year ago 83
Python Question

Can a Tkinter button have children?

I have the following code to create a button in Tkinter:

button = Button(self.parent_frame, width=100, height=100)
frame = Frame(button)
label = Label(frame, text="This is a button")
frame.pack(fill=BOTH, expand=1)
label.pack(fill=BOTH, expand=1)

When I hover my mouse over some parts of the button, the button rapidly resizes to the width of the window and then back to its initial size. Why does this happen? Is a Tkinter button not allowed to have children?

Note: I am not planning on using a frame inside a button, I am just asking this for hypothetical purposes. So instead of answers suggesting workarounds, I would prefer explanations as to why this happens.

Answer Source

Theoretically, yes, a button can have children. I suspect the behavior is undefined for platforms that use native widgets (ie: OSX and Windows).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download