Recommended Books

Python GUI



At some point in your programming career, you’ll get tired of having your results output on the console window. This is especially true if you’re trying to make a user-friendly interactive software application. This where the Python GUI comes in.

What is a 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.

For instance, Windows, an extremely common Operating system, is also a form of GUI. Windows provides us with an interface through which we can personalize, access, use and develop our PC’s.


Python GUI Libraries

Python has several third party libraries through which we can create GUI’s. We’ll be discussing two such libraries here right now.

Tkinter:

A 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 that. 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 GUI libraries.

Furthermore, tkinter is more desktop oriented in comparison to the mobile platform and has less cross platform support than some other GUI libraries. So if any of things matter greatly to you, you might want to pick another GUI library.

PyQt:

Another great Python GUI library with great cross platform support. The things you learn in PyQt will also translate directly when working with other languages so that’s a significant plus point. It’s known as a stable and mature library with many features.

Some downsides to PyQt include the fact that it’s not natively bundled with python, so you have to take care of packaging it yourself. Another issue is that PyQt is only available under the GPL. This basically means that anything you make and want to release using PyQt must be open-source. If you ever want to make a commercial application using this, you’ll have to purchase a commercial license.


Another honorable mention is Kivy which is known to be good for developing for Android and touchscreen devices. If you’re developing a GUI for a mobile app, Kivy is the way to go.

We’ll be going using Tkinter as the library of choice through out the GUI section. Mostly due to it being simpler to pick and set up than other libraries. Once you’ve got the hang of it, and you want something more powerful, you can switch over to other more advanced libraries like PyQt.


Widget Compilation:

Tkinter is massive Python GUI library, and we can’t possibly hope to fit it into a single page or even a few.

Tkinter utilizes “widgets”, like the entry box widget, message box and checkbox. Each widget further has over a dozen different options and many ways to use them. We’ll be covering just about all the widgets in tkinter (around a dozen). One page will be dedication to each widget and it’s use.

See below for a list of some tkinter widgets, links to their respective pages and a brief description for each one of them.

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.

Check Button: A check button is a Tkinter GUI widget that presents to the user a set of predefined options. The user may select more than one option.

Radio Button: A radio button is a Tkinter GUI widget that allows the user to choose only one of a predefined set of mutually exclusive options.

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.

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 tk().


This marks the end of the Python GUI with Tkinter Article. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the above material can be asked in the comments section below.

Leave a Reply

Your email address will not be published. Required fields are marked *