![]() ![]() ![]() R_lbl = tk.Label(text="""This label is a children to the default master,Īs it lacks the first positional argument for an explicit parent Toplevel.title("This is a Toplevel, whose parent is root"), Root.title("This is the actual Tk instance, root") Secondly, even if python wasn't case sensitive, it would still throw an error as it is a method and it lacks the first positional argument, which is the object instance to the class of which the winfo_toplevel method is also defined for.Įssentially, you're trying to use a case-insensitive spelling of a method, as if it is a class name such as Toplevel or Tk, which winfo_toplevel has almost nothing to do with.Įxamine the following code: import tkinter as tk In the code piece above, unless imported or otherwise defined winfo_Toplevel has no meaning, first of all, it's not as same as winfo_toplevel as python is case sensitive. On the second part, winfo_toplevel refers to the automatically created Tk instance again and creates other children with that automatically created Tk as the parent, which should be technically fine but would be harder to maintain as a code, than the standard ways of creating the same GUI I'd presume. When a parent gets destroyed all widgets that are under it also gets destroyed, so when you close the unwanted widget that is an instance of Tk, the Toplevel instance also gets destroyed as its parent is destroyed. Additionally, when a widget gets created with the absence of master option, it is assumed that the instance is a child of one of the Tk instances, in above case, there's only one, and that's the one that got automatically created. When you create any widget with the absence of an actual Tk() instance, a Tk() instance automatically gets created, thus resulting in an unwanted Toplevel-like widget when the second part of the first code snippet runs. What is actually happening here and how to ![]() On closing unwanted widget, "Window widget" isĪlso getting destroyed. On closing "Root", two widgets are created with one titled "Window widget" and On running above code "Root" widget is getting created. Looking for really a better understanding. What and when should one be used effectively. What is the exact difference between Tk(), Toplevel() and winfo_Toplevel(). NameError: name 'winfo_Toplevel' is not defined However, below snippet is not working: winf = winfo_Toplevel()Īnd returning such error: winf = winfo_Toplevel() But would like to know what it does actually. Here, my assumption is, Frame plays a role of creating widget and winfo_toplevel() is an enhancing tool to other tkinter items. On the other hand, this code is using winfo_toplevel() where the widget looks perfectly fine. _cascade(label = "File", menu = self.subMenu1) What is actually happening here and how to overcome? On closing unwanted widget, "Window widget" is also getting destroyed. On closing "Root", two widgets are created with one titled "Window widget" and other being unwanted. Even though, I had taken a look on this answer that still leaves me with confusion (and it hadn't said anything about winfo_toplevel too). And I found above three functions are getting used in creating a widget, yet I couldn't come up with the difference and the advantage of one over the other. I am trying to understand how a widget is being created. ![]()
0 Comments
Leave a Reply. |