GUIs in Python: Tkinter

Sam Dedes
3 min readJan 27, 2021

This article provides a general overview of the use and purpose of Tkinter.

A “headless program,” if you aren’t familiar, is one that has no graphical user interface (aka GUI). You may think of this as a “no fun” or “unfriendly” program. Many programming language tutorials include the creation of a rudimentary calculator, coding the calculator’s functionality in a text file, and using “input” or an equivalent to have the user interact directly command line. While a calculator program using the input function is relatively simple to implement, there is much to be desired for user experience, and it bears little resemblance to a traditional calculator. For example, it requires the user to interact with the command line, meaning the user must provide valid input, lest they cause errors which break the code. In order to provide more elegant user and program interation, various libraries, packages, and user software have been developed.

Interface comparison: Command line calculator vs GUI calculator

Generally speaking, there are two types of tools for creating GUIs: programming languages capable of creating GUIs, and software with interfaces being GUI’s themselves (which are what many traditionally think of when they hear “program”).

Some of the available software with GUI platforms are JForm Designer, Caretta, and Balsamiq, fashioning relatively shallow learning curves and intuitive interfaces. While these are useful in their own rite, their use and functionality are fundamentally different than utilizing programming languages for the construction of GUIs.

Of the programming language alternatives, Java and C++ are very popular tools for GUI construction. Various games and applications are written in Java, including Minecraft, the best-selling game to date. While C++ is sometimes seen as an aging language, it still offers plenty of usefulness and functionality, comparable to Java. Generally speaking, Java and C++ both require multi-threading in the construction of applications. (For those unfamiliar, you can think of threading as a priority list, allowing for quicker processes to run alongside their more demanding compatriots.) This improves program efficiency and avoids some of the lag which arising in applications from particularly intensive tasks in the code.

In contrast, Python is unique in that it doesn’t require threading. This offers some convenience, however, in practice multi-threading is necessary for a smoothly running, functional GUI beyond rudimentary complexity. Luckily, the magnificently named python library “threading” allows for multi-threading, and other tools necessary for improving performance.

This brings us to the package of interest, Tkinter. This library provides a platform to build GUI’s, rather than requiring command line or editor interaction to utilize program functionality. Tkinter is a great tool for applications of low to moderate complexity. It allows for a type of “default” construction of GUIs, where the library will provide an automatic layout for text, buttons, and windows. Subsequently, many parameters need not to be specified making it an excellent way to get started on your first GUI.

A window with text created with Tkinter

There are several python packages available that allow for functionality similar to Tkinter, including PySimpleGUI, PyQt, and PySide. These packages have their own methods, classes, and intended uses. These packages available lend themselves for larger and more complex interfaces, and at that, possible topics for future posts.

Tkinter was originally developed by Fredrik Lundh, and is included in the standard Python library. This is Python’s standard Tk toolkit interface (hence tkinter). Tk is a cross-platform toolkit which includes the tools necessary to construct simple GUIs. You can find Tkinter’s python documentation here: https://docs.python.org/3/library/tkinter.html#file-handlers

--

--