Shubham Sarda

There is a rich ecosystem of Python GUI frameworks that provide a variety of choices for displaying data and interacting with a program. The standard interface in most Python programs is the command line, which is incredibly powerful, but often too cryptic for beginners. For this reason, there are several different graphical user interface frameworks that can be used to make it easier to interact with a Python program.

Python GUI libraries provide a selection of tools to create graphical user interfaces. These tools range from an API for building cross-platform desktop applications to integrated development environments that facilitate rapid prototyping.

What is a Python GUI?

A graphical user interface, or GUI for short, is the way you interact with your computer through icons and menus on the screen instead of typing commands into a command-line prompt. GUI frameworks provide developers with a variety of windows and other graphical elements that they can interact with to provide a user friendly experience.

Python GUI Programming Using Tkinter and SQLite3

Last Updated June 2022

  • 37 lectures
  • All Levels
4.7 (74)

Python Hands On Project – Building Crypto Currency Portfolio App With Python 3, Tkinter, SQLite3 And CoinMarketCap API. | By Shubham Sarda

Explore Course

There are many options available to help you build the interface for your app. In this post, we’ll take a look at some of the most popular ones: Tkinter, PyQt5, Kivy, wxWidgets, and PySide. These frameworks for Python handle the UI aspects of an application and allow developers to focus on just the functionality they want to build into the app.

Tkinter

Tkinter is a cross-platform widget set for creating graphical user interfaces written in Python. The Tkinter module provides a great deal of functionality, including geometry managers, customized widgets, theming support, and Unicode text handling. Tkinter is designed to be easy to use while still providing features comparable to other GUI toolkits.

For developers with no GUI building experience, Tkinter can be a great way to get started with building your own applications in Python. It provides a lot of features out of the box, making it great for prototyping or small projects, and doesn’t require you to invest a lot of time. However, this comes at the cost of having limited customization options. If your project requires more advanced features than what Tkinter offers, then commercial frameworks like PyQt5 will help.

Tkinter Installation

Tkinter is a built-in library; you don’t need to install it like other GUI frameworks. If you have Python, you already have Tkinter.

Top courses in Python

Python for Data Science and Machine Learning Bootcamp
Jose Portilla
4.6 (120,734)
Bestseller
Machine Learning A-Z™: Hands-On Python & R In Data Science
Kirill Eremenko, Hadelin de Ponteves, Ligency I Team, Ligency Team
4.5 (162,156)
The Modern Python 3 Bootcamp
Colt Steele
4.7 (26,914)
Python for beginners
Bharath Thippireddy
4.4 (20,900)

More Python Courses


Tkinter Code Example

from tkinter import *

class Root(Tk):
    def __init__(self):
        super(Root,self).__init__()

        self.title(“Tkinter Window Example”)
        self.minsize(500,400)

root = Root()
root.mainloop()

Tkinter Output

Tkinter Window
Tkinter Window

Pros of Tkinter

Cons of Tkinter

PyQt5

Qt is a well-known C++ GUI library, and PyQt5 is a Qt for Python. It uses the Qt framework to provide stable, well-documented, and thoroughly tested Python bindings. PyQt5 works on all major platforms including Linux, Windows, and Mac OS X. The API is designed to be an easy-to-use replacement for other C++ GUI toolkits with a 10X time reduction in application development time, so you can rapidly develop rich applications locally or on embedded devices. In addition, it provides many useful features such as automatic memory management, threading support, signal/slot connections, and more. However, one major drawback associated with PyQt5 is the commercial license requirement to function as a commercial project. 

PyQt5 Installation

To install pyqt5, run the following pip Python command:

pip install pyqt5

PyQT5 Code Example

from PyQt5.QtWidgets import QApplication, QMainWindow
import sys

class Window(QMainWindow):
  def __init__(self):
      super().__init__()

      self.setGeometry(200, 400, 400, 200)
      self.setWindowTitle(“PyQt5 Window Example”)
      self.show()

app = QApplication(sys.argv)
window = Window()
sys.exit(app.exec_())

PyQT5 Output

PyQt5 Window
PyQt5 Window

Pros of PyQT5

Cons of PyQT5

Kivy

Kivy is a cross-platform GUI library for developing multimedia applications using multi-touch interfaces in Python. Kivy allows widgets to work across multiple platforms without having to write any native code. The graphics engine of Kivy is built over OpenGL ES 2, using a modern and fast graphics pipeline, which makes this framework suitable for designers of iOS and Android apps. The main advantages are that the user interface can be written in pure Python. This means no C++ knowledge is required, and there is very little overhead compared to other frameworks.

Kivy was originally developed to work on the Raspberry Pi and other low power and embedded devices, and now, more of its functionality can be used on more powerful desktop computers. Its focus is graphics rendering, animation, packaging, user interaction, and more. Kivy is also a framework that offers an extensive array of widgets for displaying data and communicating with the user.

Kivy Installation

To install Kivy, run the following command in your terminal:

pip install Kivy

Kivy Code Example

from kivy.app import App
from kivy.uix.button import Button


class TestApp(App):
    def build(self):
        self.title = ‘Kivy Window Example’
        return Button(text=”Hello Kivy World!”)


TestApp().run()

Kivy Output

Kivy Window
Kivy Window

Pros of Kivy

Cons of Kivy

wxPython

wxPython is a Python GUI toolkit, written in C++, that can be cross-platform. It is an open-source project maintained by the wxWidgets team. Being a part of the larger wxWidgets project, it has been designed to be compatible with both Windows and Linux development environments. 

The main goal of this library is to provide Python developers with high-quality widgets for their GUI applications. This includes native controls such as text boxes, checkboxes, buttons text, list views, and other standard components, but also more complex components like frames or dialog boxes. In addition, there are many other features available, including drag-and-drop support, file browsing, printing, clipboard operations, internationalization, and more. The library also includes an extensive collection of entry widgets that are used to build GUIs with ease. In addition, it supports many other features, such as event handling, threading, internationalization, and other advanced features not included in many of these other frameworks. These features make WxPython one of the most popular GUI toolkits available today. 

wxPython Installation

To install wxPython, run the following command in your terminal:

pip install wxPython

wxPython Code Example

import wx

app = wx.App()
frame = wx.Frame(parent=None, title=’wxPython Window Example’)
frame.Show()
app.MainLoop()

wxPython Output

wxPython Window
wxPython Window

Pros of wxPython

Cons of wxPython

PySide

PySide is a Qt-based framework that allows you to write applications using PyQt or PySide components. The main advantage of this toolkit over other alternatives such as wxWidgets is its ability to be embedded into any C++ project without requiring additional dependencies. It also provides many useful widgets for creating user interfaces. However, it has some limitations when compared with other toolsets like Tkinter. For example, there is no built-in support for dialog boxes or menus. Also, it does not have a good documentation system. PySide is based on QT, but doesn’t require a commercial license like PyQT5.

Pyside Installation

To install Pyside, run the following command in your terminal:

pip install PySide2

Pyside Code Example

from PySide2.QtWidgets import QtWidgets, QApplication
import sys

class Window(QtWidgets):
    def __init__(self):
        super().__init__()

        self.setWindowTitle(“Pyside2 Window Example”)
        self.setGeometry(300,300,500,400)

app = QApplication(sys.argv)
window=Window()
window.show()
app.exec_()

Pyside Output

PySide2 Window
PySide2 Window

Pros of Pyside

Cons of Pyside

Conclusion

A few things should be considered if you are using Python GUI tools. Tkinter, WxPython, PySide, and Kivy are free Python libraries that can be used in any program. PyQT, on the other hand, requires a license for you to use it in commercial projects. Also, Tkinter is included in the standard Python library and doesn’t require any additional installation, while the other four require separate installation.

Which GUI framework you choose depends on your needs and preferences. Tkinter is the simplest to learn and use, with a moderate learning curve and a wide range of features. wxPython is more complex but also more powerful. PyQt is somewhere in between but requires a license for commercial projects.

If you are wondering what python is used for in addition to GUI development, Python is also used for data science, data analysis, artificial intelligence, web development, and scientific computing. And if you are looking for projects to build using one of these Python GUI frameworks, visit Udemy’s article on Python project ideas.

Page Last Updated: April 2022