Skip to content Skip to sidebar Skip to footer

Parent/master Vs. In_ In Tkinter

Examine the following code: import Tkinter as tk root=tk.Tk() f1 = tk.Frame(width=200, height=200, background='red') f2 = tk.Frame(width=100, height=100, background='blue') f1.p

Solution 1:

What is the difference between the hierarchy created by the master parameter used in the instantiation of new widgets and the hierarchy created by the the in_ prameter used in the .place layout manager?

The simple answer is that there is no hierarchy created by the in_ parameter. The only hierarchy is the parent/child relationship when the widget is created.

The in_ parameter merely identifies a widget into which the other widget should be placed. It tells tkinter "make this child's placement relative to this other widget".

Why is f2 not being created as a child of f1? (and would it change anything?)

It's not being created as a child because you didn't tell it to be a child. You didn't specify a parent, so tkinter uses the root window as the parent.

Would it change anything if you did? Not in this specific case. If f1 did not fill the whole window, or filled it asymmetrically, f2 would appear centered in f1 but not centered in the window as a whole.

Solution 2:

My lack of understanding seems to have been the result of a problem in my code for which I got an answer here: tkinter placement of widgets

Getting rid of the issue describe there I can now see that:

Master/parent: defines a bounding area limiting the rendering of its child widgets

in_: sets the widget on which the positioning of the in_(cluded) widget would be based

Post a Comment for "Parent/master Vs. In_ In Tkinter"