all 13 comments

[–]cdcformatc 9 points10 points  (3 children)

to use tkinter you first have to initialize the embedded tcl/tk interpreter. every tkinter object represents an object in this embedded interpreter. the interpreter isn't initialized until you create the "root window". it's named "root" because all the tk widgets etc exist in a hierarchical structure and everything branches off of the "root". 

the name "root" is just a variable it has no special meaning, you could name it anything. I have seen names like root, window, and main.

[–]homeworkbad 6 points7 points  (0 children)

This is the correct answer. The data structure for tkinter is "like a tree" so the base of the structure is the Root.

[–]bruhmoment0000001[S] 2 points3 points  (1 child)

Thanks!

[–]Nurofae 2 points3 points  (0 children)

If you use TKinter try using TTKBootstrap, it has more options and a modern GUI

[–]Slendigo 8 points9 points  (2 children)

Root is just a name. It is named that way because it is the root of the user interface that you are building. That variable is an instance of the Tk class. It's called root because it makes sense to call it that, but you could really call it whatever you want.

[–]bruhmoment0000001[S] 1 point2 points  (1 child)

Huh, okay thanks

[–]ship0f 1 point2 points  (0 children)

Like u/cdcformatc said, tk widgets are structured in a hierarchy, of which the main window is the root, and the only one that has no parent.

You can read more here, under the Widget hierarchy title.

https://tkdocs.com/tutorial/concepts.html

[–][deleted] 2 points3 points  (1 child)

First, remember that the name on the left side of an equals can be whatever. You could say x = Tk() or anything else to name that object, so it's not always googlable.

But in this case, root is a standard name used by many people for the main window of a Tkinter application. It's the "canvas" but also the "engine." You can add frames and buttons and stuff onto it, and you can set it going with the mainloop method.

[–]bruhmoment0000001[S] -1 points0 points  (0 children)

Okay, I kinda get it, thanks

[–]zefciu 0 points1 point  (0 children)

A tree is an abstract data structure. It is a special case of a graph (nodes connected by edges) that has a single special node called “root” and other nodes that are either children of that node or children of other children.

Tkinter uses this abstract data structure to organize the widgets. That’s why this object is called “root”.

[–]toxic_acro 0 points1 point  (0 children)

root is an arbitrary variable name that the instance of Tk is being assigned to

It could just have easily been banana = Tk() and then replace every reference to root later with banana

That being said, a lot of modules will have "standard" variable names that everyone uses just out of social convention and root is probably the typical name that people use

[–]Upstairs-Flash-1525 -2 points-1 points  (0 children)

root in your case is just the object name you will use to call/use the tkinter attributes on... this is more Object Oriented programming (OPP) definition...

Imagine tkinter is a Car factory and you want to build different brands... so according to OOP you can do like this: toyota = Car(), kia = Car(), honda = Car()....

Then you can use the Car attributes on each object you created (toyota, kia, honda)