# create GUI
app = Tk()
app.title("Head-Ex Deliveries")

# create a label
Label(app, text = "Depot:").pack() # add to Tk app window

# create a text entry
depot = Entry(app)
depot.pack()

I understand and have been told that placing the instance name(app) as a parameter of Tk methods and other Tkinter methods results in attaching those objects to the "app" Window. But what I want to know is why and how this works, this has never been explained to me.
For instance, Label as seen above, is a class, and as I've been told placing a class name within the parameter of another class makes it an inherited class. But I don't recall ever being told what happens when you place an instance of one class as the parameter of another. So I'M stuck trying to figure out why and how this works. Thanks.

In principle it is like any other parameter. It goes to objects creation method __init__which makes that object parent or 'holder' of the new widget. So it has nothing to do with inheriting but way off defining the hierarchy of widgets.

Edited 6 Years Ago by pyTony: n/a

When you say "It goes to objects creation method __init__", do you mean object of Label or object app of Tk()? I'M still finding this confusing.

It goes to objects creation method __init__

I think, he means something like, __init__ will create the frame and the main things to be able to put widgets into the application. But __init__ creates, like the parent window (normally), and then you can have the called (child) windows into the parent one, and normally it's the parent window that calls the other child windows and widgets, am I right?

What almost all GUI systems are is one continuous loop checking events from user and system. It is called event loop and in tkinter it is started by mainloop method. GUI programming is often referred as event driven programming because of that. Creating widgets puts the widgets in the list of things that gui takes care. The parameter in widget creation helps the GUI to know under which widget the new widget belongs in the hierarchy of things, which decides who handles events and where it is drawn in window by the pack or grid.

Any help, or more confusing?

Edited 6 Years Ago by pyTony: n/a

This article has been dead for over six months. Start a new discussion instead.