Open In App

Python GUI – PyQt VS TKinter

 A GUI toolkit contains widgets that are used to create a graphical interface. Python includes a wide range of Interface implementations available, from TkInter (it comes with Python, ) to a variety of various cross-platform solutions, such as PyQt5, which is known for its more sophisticated widgets and sleek look. 

PyQt

PyQt is a toolkit for graphical user interface (GUI) widgets. It is extracted from the library of Qt. PyQt is the product of the combination of the Python language and the Qt library. PyQt is coming with the Qt Builder. We will use it to get the python code from the Qt Creator. With the support of a qt designer, we can build a GUI, and then we can get python code for that GUI. PyQt supports all platforms including Windows, macOS and UNIX. PyQt can be used to create stylish GUIs, a modern and portable python framework. 



Code:




# Import sys for handle the 
# exit status of the application.
import sys
  
# Importing required widgets
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QWidget
  
# To create an instance of QApplication
# sys.argv contains the list of
# command-line argument
app = QApplication(sys.argv)
  
# To create an instance of application GUI
# root is an instance of QWidget,
# it provides all the features to
# create the application's window
root = QWidget()  
  
# adding title to window
root.setWindowTitle('Geeks App'
  
# to place txt at the coordinates
root.move(60, 15
  
# to display text
txt = QLabel('Welcome, Geeks!', parent = root) 
txt.move(60, 15)
  
# Show application's GUI
root.show()
  
# Run application's main loop
sys.exit(app.exec_())

Output:



A simple app to display text using PyQt.

Advantages of using PyQt

Disadvantages of using PyQt

Tkinter

Tkinter is an open-source Python Graphic User Interface (GUI) library well known for its simplicity. It comes pre-installed in Python, so you don’t even need to think about installing it. These characteristics make it a strong position for beginners and intermediates to begin with. Tkinter cannot be used for larger-scale projects.

Code:




# importing the module tkinter
import tkinter as tk
  
# create main window (parent window)
root = tk.Tk()
  
# Label() it display box
# where you can put any text. 
txt = tk.Label(root,
               text="Welcome to GeekForGeeks")
  
# pack() It organizes the widgets
# in blocks before placing in the parent widget.
txt.pack()
  
# running the main loop
root.mainloop()

Output:

A simple app to display text using tkinter.

Advantages of using Tkinter

Disadvantages of using Tkinter

Difference between PyQt and Tkinter

No. Basis

PyQt

Tkinter

1. License PyQt is available under Riverbank Commercial License and GPL v3 (General Public License v 3.0) and if you do not wish to release your application under a GPL-compatible license, you must apply for a commercial license.  Tkinter is open source and free for any commercial use.
2. Ease of Understanding It requires a lot of time for understanding all the details of PyQt. Tkinter is easy to understand and master due to a small library.
3. Design PyQt has a modern look and a good UI. Tk had an older design and it looks outdated.
4. Widgets thenPyQt comes with many powerful and advanced widgets.   TkInter does not come with advanced widgets.
5. UI Builder PyQt have a Qt Designer tool which we can use to build GUIs than get python code of that GUI using Qt Designer. It has no similar tool as Qt Designer for Tkinter.
6. Installation PyQt is not included by default with Python installations. It is included in the standard Python library so no need to install it separately.

Article Tags :