I am using Python 2.7 and I wanted to know if there was a difference between the title() method and the wm_title() method for the Tkinter class. The following code:
import Tkinter as tk
root = tk.Tk()
root.title("My App")
root.mainloop()
and
import Tkinter as tk
root = tk.Tk()
root.wm_title("My App")
root.mainloop()
accomplishes the same thing. Is there something hidden that is going on?
The title in tkinter refers to a name assigned to the application window. It is mostly found on the top of the application. For this, we can use the title() function. We create a widget object using the Tk() function and use the title() function to add a title to this window.
It comes with all the modules defined in tkinter. However, to save the major typing efforts, we import the tkinter library with some acronym further that can be used to create an instance of widgets. Thus, the application structures become more aesthetical by using the import tkinter as tk.
mainloop() tells Python to run the Tkinter event loop. This method listens for events, such as button clicks or keypresses, and blocks any code that comes after it from running until you close the window where you called the method.
In order to create a tkinter application, we generally create an instance of tkinter frame, i.e., Tk(). It helps to display the root window and manages all the other components of the tkinter application. We can initialize the tkinter instance by assigning the variable to it.
Same thing really. wm
methods are used to communicate with the window manager. Hence wm
for window manager.
Wm class is used as a mixin by the root tk.Tk()
window. You can access setting the title as you have by title
or wm_title
and other window manager attributes.
You can see the documentation here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With