In this article we are going to introduce Python GUI Development Libraries, so a you know
Python is one of the best programming language, and there are different sections that you
can use Python, one of them is using Python in GUI Development. there are different GUI Libraries
in Python that you can build User Interface applications, we want to introduce the most popular
and powerful Python GUI Development Libraries.
1: PyQt5
My first choice on GUI Development with Python is PyQt5, it is one of the best and powerful
libraries in building GUI application,PyQt is a binding of Qt5 C++ a gui framework for c++
developers. you can create program in pyqt5 using coding or a using qt designer a visual dialog
that you can drag and drop UI widgets. PyQt5 is a free Python bindings software open source
widget-toolkit Qt, implemented for cross-platform application development framework. In the free
version, certain features may not be available but if your application is open source then you can use
it under a free license. PyQt is available on Windows, MacOSX, Linux, Android iOS and Raspberry
Pi.
Installation
You can use pip for the installation
1 |
pip install pyqt5 |
Creating first window in pyqt5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from PyQt5.QtWidgets import QApplication, QMainWindow import sys from PyQt5 import QtGui class Window(QMainWindow): def __init__(self): super().__init__() self.setGeometry(300, 300, 500, 400) self.setWindowTitle("PyQt5 Window") self.show() App = QApplication(sys.argv) window = Window() sys.exit(App.exec()) |
Run the complete code and this is the result
2: TKinter
If you are looking completely free library for GUI Development in Python, than your choice
will be tkinter. Tkinter is the most popular programming package for graphical user
interface or desktop apps. It is so named because of its simplicity. Tkinter is the combination
of Tk and Python’s standard GUI framework. Tkinter It provides diverse widgets, such as
labels, buttons, and text boxes used in a graphical user interface application. The Button
control also called widgets are used to display buttons in developed application while the
Canvas widget is used to draw shapes (lines, ovals, polygon…) in your application.
It is a built in library for python.
Installation
It is a built in library in python, no need to install
Creating example in TKinter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
from tkinter import * class Root(Tk): def __init__(self): super(Root, self).__init__() self.title("Geekscoders.com - TKinter Window") self.minsize(400, 300) root = Root() root.mainloop() |
Run the complete code and this is the result.
3: Pyside2 (Qt For Python)
Qt for Python offers the official Python bindings for Qt (PySide2), enabling the use
of its APIs in Python applications, and a binding generator tool (Shiboken2) which
can be used to expose C++ projects into Python. Qt for Python is available under
the LGPLv3/GPLv3 and the Qt commercial license.
Installation
1 |
pip install PySide2 |
Creating first window in PySide2(Qt For Python)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from PySide2.QtWidgets import QApplication,QWidget import sys import time class Window(QWidget): def __init__(self): super().__init__() self.setWindowTitle("Pyside2 Simple Application") self.setGeometry(300,300,500,400) myApp = QApplication(sys.argv) window = Window() window.show() myApp.exec_() sys.exit(0) |
Run the code and this is the example
4: Kivy
Kivy is Open source Python library for rapid development of applications that make
use of innovative user interfaces, such as multi-touch apps. Kivy runs on Linux, Windows,
OS X, Android, iOS, and Raspberry Pi. you can run the same code on all supported platforms.
It can natively use most inputs, protocols and devices including WM_Touch, WM_Pen,
Mac OS X Trackpad and Magic Mouse, Mtdev, Linux Kernel HID. Kivy is 100% free to use,
under an MIT license, The toolkit is professionally developed, backed and used.
You can use it in a commercial product. the framework is stable and has a well
documented API, plus a programming guide to help you get started.
Installation
Before installing Kivy, you need to install the following dependency and after that you
can install kivy.
1 |
pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew |
1 |
pip install Kivy |
Creating first example in Kivy
1 2 3 4 5 6 7 8 9 10 11 12 |
from kivy.app import App from kivy.uix.button import Label class TestApp(App): def build(self): return Label(text = "Geekscoders.com - Kivy Window") TestApp().run() |
Run the complete code and this is the result.
5: wxPython
wxPython is a cross-platform GUI toolkit for the Python programming language.
It allows Python programmers to create programs with a robust, highly functional
graphical user interface, simply and easily. It is implemented as a set of Python extension
modules that wrap the GUI components of the popular wxWidgets cross platform library,
which is written in C++.
Like Python and wxWidgets, wxPython is Open Source, which means that it is free
for anyone to use and the source code is available for anyone to look at and modify. And
anyone can contribute fixes or enhancements to the project.
wxPython is a cross-platform toolkit. This means that the same program will run on multiple
platforms without modification. Currently Supported platforms are Microsoft Windows,
Mac OS X and macOS, and Linux.
Installation
1 |
pip install wxPython |
Creating first window in wxPython.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import wx class MyFrame(wx.Frame): def __init__(self, parent, title): super(MyFrame, self).__init__(parent, title=title, size = (400,300)) self.panel = MyPanel(self) class MyPanel(wx.Panel): def __init__(self, parent): super(MyPanel, self).__init__(parent) class MyApp(wx.App): def OnInit(self): self.frame = MyFrame(parent=None, title="Geekscoders.com - wxPython Window") self.frame.Show() return True app = MyApp() app.MainLoop() |
Run the complete code and this is the result
Conclusion
All of them are good libraries, if you want powerful library than you can go with PyQt5 or Pyside2, but they are not free, if you want for commercial purposes than you need to buy the license, if you want free gui library in python than you can go with tkinter or wxPython, also kivy is another choice.