This tutorial explains how to create a Python GUI with Tkinter
Introduction to Python GUI
The GUI or Graphical User interface is a form of user interface that includes graphical elements, such as windows, icons and buttons. These allow the average user to communicate with an electronic device. The alternative is to use the command line, which is neither user friendly or visually pleasing.
Every programming language has it’s own set of unique GUI libraries. In Python, Tkinter is the most common GUI Library used to create Graphical User Interfaces.
Why use Tkinter?
Tkinter is an open source Python GUI library known for it’s simplicity and flexibility. It comes pre-installed in Python 3 so you don’t even have to worry about downloading it. These qualities make it a strong starting point for the beginner and intermediate levels. Not to say that tkinter can’t be used on larger scale projects. If you master tkinter, you can produce GUI on par with other more complex and modern GUI libraries.
There are many alternatives to Tkinter such as PyQt5 which is known for it’s more advanced widgets and modern look. You can learn PyQt5 using our very own PyQt5 tutorial series if you wish to, here on CodersLegacy.
Tkinter Widget Compilation:
Tkinter utilizes “widgets” which refer to individual GUI elements like the entry widget, messagebox widget and checkbox widget. Each widget further has over a dozen different options and many ways to use and manipulate them. We’ll be covering just about all the widgets in the Tkinter GUI Library (around a dozen). One page will be dedicated to each widget and it’s usage.
Python Tkinter Widgets:
Frame: Outlines the frame for your Tkinter window with a fixed size. Just like the human skeleton, a Tkinter window requires a frame to support it and give it structure.
Buttons: The Python Tkinter Button is a standard Tkinter widget. A button is used as a way for the user to interact with the User interface. Once the button is clicked, an action is triggered by the program.
Entry: A standard Tkinter widget used to take input from the user through the user interface. A simple box is provided where the user can input text.
Label: A Tkinter widget used to display simple lines of text on a GUI.
Menu: The Tkinter Menu widget is used to create various types of menus in the GUI such as top-level menus, which are displayed right under the title bar of the parent window.
ComboBox: A special extension of Tkinter,
ttk module brings forward this widget. A combobox presents a drop down list of options and displays them one at a time. Has a more modern approach than other similar widgets.
List Box: Another Tkinter widget that is used to display a list of options for the user to select. Displays all of the options in one go. Furthermore, all options are in text format.
Menu Button: A combination of both the button and menu widget, this button widget displays a drop down menu with a list of options once clicked.
Canvas: One of the more advanced Tkinter widgets. As the name suggests, it’s used to draw graphs and plots on. You can even use images in a Canvas. It’s like a drawing board on which you can paint/draw anything.
Scale: The Tkinter Scale widget is used to implement a graphical slider to the User interface giving the user the option of picking through a range of values.
Scrollbar: A useful widget in GUI’s, which allows you to scroll in a Tkinter window or enable the scroll feature for certain widgets.
File Dialogs: File Dialogs has a rather unique function in Tkinter. They give the user the option to select/save a file/directory from their computer through the use of a “Dialog” (The dialog that appears when you click on “open file” or “save file”). It’s good looking, fast and user friendly and comes in handy often.
Toplevel: A widget in Tkinter that allows for the easy spawning of new Tkinter Windows. Toplevel is a better alternative to spawning extra tkinter windows by using
Bonus Tkinter Articles:
A Python GUI library like Tkinter has alot to offer besides the above widgets. Below are some extra features, functions and (minor) widgets that are less common, but are irreplaceable in what they do.
- How to delete widgets in Tkinter
- How to close a Tkinter window (programatically)
- Disable resizing for a Tkinter window
- Customize Tkinter Font
- Emptying out the Entrybox contents
- Creating a color chooser
- Tkinter Grid Placement
This marks the end of the Python GUI with Tkinter Article. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the tutorial can be asked in the comments section below.