6

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.

null
  • 2,060
  • 3
  • 23
  • 42
  • is this a tkinter button or a ttk button? Also, what platform are you seeing this on? technically speaking a button can have children, though that may not work on OSX, and it may not work with ttk buttons. – Bryan Oakley Nov 17 '16 at 18:41
  • It's a Tkinter button, and I am on Windows 10. – null Nov 17 '16 at 18:45
  • Check out this discussion thread: https://mail.python.org/pipermail//tkinter-discuss/2012-May/003141.html – Mixone Nov 17 '16 at 19:38
  • Doesnt really have an answer I beleive but some of the comments might be helpfull into getting some insight – Mixone Nov 17 '16 at 19:39

1 Answers1

1

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

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685