Python provides a variety of GUI (Graphic User Interface) such as PyQt, Tkinter, Kivy and soon. Among them, tkinter is the most commonly used GUI module in Python since it is simple and easy to learn and implement as well. The word Tkinter comes from the tk interface. The tkinter module is available in Python standard library.
Note: For more information, refer to Python GUI – tkinter
For Ubuntu, you have to install tkinter module by writing following command:
sudo apt-get install python-tk
When a Tkinter program runs, it runs a mainloop (an infinite loop) which is responsible for running a GUI program. At a time only one instance of mainloop can be active, so in order to open a new window we have to use a widget, Toplevel.
A Toplevel widget works pretty much like a Frame, but it opens in a separate top-level window, such windows have all the properties that a main window (root/master window) should have.
To open a new window with a button, we will use events.
Example 2: This will be a class based approach, in this we will create a class which will derive Toplevel widget class and will behave like a toplevel. This method will be useful when you want to add some other properties to an existing Toplevel widget class.
Every object of this class will be a Toplevel widget. We will also use bind() method to register click event.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course