Professional Documents
Culture Documents
A Brief Demonstration of Some Python GUI Libraries
A Brief Demonstration of Some Python GUI Libraries
2.1 Tkinter
Tkinter is a Python interface to the Tk GUI li-
brary and has been a part of the Python stan-
dard library since 1994 with the release of
Python version 1.1, making it the de facto GUI
library for Python [6]. The Tk widget library
originates from the Tool Command Language
(Tcl) programming language. Tcl and Tk were
created by John Ousterman in the late 1980s
as an easier way to program engineering tools Figure 1. The root window
while being used at the university. Tkinter
is nowadays arguably the most common GUI These three lines (excluding commented line)
framework in Python GUI library. The features result in the root window (shown in Fig. 1)
that make it a great choice for GUI program- appearing on the screen. In the first line of
ming include the following [7],[8]: code we just import the tkinter module into
the namespace. After that, all its definitions of
• It is quite simple to learn (simpler than the classes, attributes and methods can be ac-
cessed. The second line created the root win-
any other GUI package for Python). dow, which is an instance of tkinter.Tk class.
The third line is just a comment, where we will
• Relatively little code can produce power- be later adding other code. The forth line is an
ful GUI applications. event loop method of the root object and keeps
the root window visible. Without it, the win-
• Layered design ensures that it is easy to dow created in the second line would disappear
grasp. too fast. In order to make some useful applica-
tion using Tkinter, we need widgets. Tkinter
includes 21 core widgets, as shown in Tab. 1.
• It is portable across all operating systems. The code for an example using Label and But-
• It is easily accessible, as it comes pre- Table 1. The Tkinter’s 21 core widgets [7]
installed with the standard Python distri-
bution. Top-level Label Button
Frame LabelFrame Listbox
Menu Menubutton Message
• Code can be written both procedurally or
OptionMenu PanedWindow Radiobutton
using object-oriented practices (which is Scale Scrollbar Spinbox
the preferred style for anything nonexper- Text Bitmap Image
imental).
ton widgets of Tkinter is stated below:
It might seem at first sight that Tkinter is not
going to do well, because the Python inter- import tkinter as tk
preter is using the Tkinter module which, in class Window(tk.Tk):
turn, uses the tkinter interface, which then calls def __init__(self):
Tcl and Tk libraries and sometimes also the Tcl super().__init__()
interpreter in order to bind properties to wid- self.title("Hello Tkinter")
gets [9]. Despite this it is performing very well self.label = tk.Label(self,
on modern computers. It should be noted, that text="Choose One")
starting from Python 3, the Tkinter module was self.label.pack(fill=tk.BOTH,
renamed to tkinter [10]. An outline for its ap- expand=1, padx=100, pady=10)
plication is shown in the following code [12]: hello_btn = tk.Button(self,
text="Hello", command=self.hello)
import tkinter hello_btn.pack(side=tk.LEFT,
root = tkinter.Tk() padx=(20, 0), pady=(0, 20))
# Code to add widgets ... goodbye_btn = tk.Button(self,
root.mainloop() text="Goodbye", command=self.goodbye)
a 1
Y (s) = · (3)
(s2 + 2s + 1)(s + 3) s result shown in Fig. 9. On this example we
The partial fraction expansion, the inverse can clearly see the advantages of the applica-
Laplace transform y(t) and its graph can be ob- tion of GUI (in this case made with Ipywidgets
tained by the following code: library) for system response analysis purposes.
[12] https://www.tutorialspoint.com/python3/index.htm
4 CONCLUSION
[13] https://pysimplegui.readthedocs.io/en/latest/
In the paper four popular Python GUI libraries
are briefly presented. Their way of application [14] https://pysimplegui.readthedocs.io/en/latest/cookbook/
is similar in some respects but different in oth-
[15] https://flexx.readthedocs.io/en/stable/
ers. Mainly the personal preference determines
which library is preferred by each individual. [16] https://ipywidgets.readthedocs.io/en/stable/
In this paper only the most basic examples are
presented for each GUI library. Two educa-
tional examples are also presented.
In future it would be interesting to make a re-
search of more GUIs and not only compare
them based on the (visual) preference, but also
based on the performance and versatility.
REFERENCES
[1] https://www.tiobe.com/tiobe-index/
[3] https://techsore.com/best-python-gui/
[4] https://insights.dice.com/2017/08/07/7-top-python-
gui-frameworks/
[5] https://unwiredlearning.com/blog/top-python-gui-
frameworks/