Click here to Skip to main content
15,881,204 members
Articles / Desktop Programming / QT

PyQt vs Tkinter – The Better GUI Library

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
9 Aug 2020CPOL6 min read 19.8K   4   5
Comparison of PyQt and Tkinter
In this article, I’m going to share my own journey and personal experience with two GUI libraries, PyQt and Tkinter. I have also included a side by side comparison of Tkinter and PyQt GUI’s with the same widgets.

This article compares two Python GUI libraries, PyQt vs Tkinter.

The PyQt vs Tkinter debate is one I’ve been seeing ever since I joined up with several Python communities and social media sites. In this article, I’m going to share my own journey and personal experience with these two GUI libraries.

Besides my personal experience, I’ve included a side by side comparison of Tkinter and PyQt GUI’s with the same widgets. Most GUI’s have the same widgets like Labels, Buttons, CheckButtons and Menus so this makes the comparison a lot easier.

By the end of this article, the difference between these two libraries will be made clear. If you haven’t begun using either yet, this article will help you make that decision.

Tkinter

First Impressions

Tkinter was the first GUI library I started out with. I was unaware of any other GUI libraries like PyQt. I used Tkinter for many simple projects, and the experience was pretty good. It’s part of the Python Standard Library so you don’t have to worry about downloading and installing it either. It was simple to learn, and by the end of it I could create a simple GUI with several functioning widgets in under 10 minutes.

Widgets

Even before I came across other GUI libraries, Tkinter’s widgets felt rather old fashioned. They remind me of the kind of GUI I would see in software of the 2000’s. Another issue I had with Tkinter was a slight screen blurriness issue for which I had to use the ctypes library to fix.

Putting aside the looks however, Tkinter has a fairly large number of widgets and support for menus. One widget that’s rather unique to Tkinter is the Canvas widget which is like a drawing board where you can display images and draw graphs, etc. Overall, Tkinter does fairly well in the widgets category if you put the looks aside.

Miscellaneous

Tkinter has a special module called ttk which was released alongside Tkinter 8.5. The ttk module has its own Button, Check Button, Entry, Frame and more Widgets. Importing this module will automatically overwrite the Tkinter variants. The ttk widgets have a more modern and sleek look to them and are fully compatible with Tkinter.

You can begin learning Tkinter with our Tkinter Tutorial Series.

PyQt

First Impressions

As my programming knowledge and outreach grew, I began to hear about other GUI libraries. I would sometimes come across posts and questions by people asking for a library with a more “modern” look than Tkinter. Other experienced devs would often recommend PyQt as the better alternative, leading to me begin my PyQt journey.

The first thing I noticed with PyQt that the number of tutorials and guides for it were considerably lower than that for its competitor Tkinter. In fact, some of these tutorials were actually for the outdated PyQt4, instead of its newer PyQt5 version. This is actually a factor that drove me to develop my own Tutorial series on PyQt.

Another experience I had while coding is that PyQt5 is harder to debug than Tkinter. Sometimes if there was a syntax error or bug present in my code, the GUI window would just shutdown with no warning and no error message. This did however became less of an issue as I became more familiar with the library and its syntax.

Furthermore, the initial startup time for a PyQt5 application is actually more than that for a Tkinter application of similar size. Despite only a few widgets present, PyQt5 would sometimes take almost twice the time to display compared to its Tkinter equivalent.

Widgets

Now, onto the actual PyQt code. My first impression of it was that it was significantly lengthy as compared to Tkinter. Creating and customizing a single widget in PyQt could take up more than 5 lines. Whereas in Tkinter, I would require 3 lines max. In PyQt’s defense however, its lines were shorter and simpler to understand (individually) so it sort of balances out.

The difference in GUIs was pretty clear. Even before I created any widgets, looking at the PyQt display window, I could tell that it was superior. It looked cleaner and sharper unlike Tkinter which gave me this blurry kind of look. If I had to describe PyQt’s window in a single word, it would be “sleek”.

PyQt5 also has a larger number of number of widgets. Most of widgets of PyQt and Tkinter are the same, but PyQt wins out in the “special widgets” category. Examples of these are the QProgressBar, QSpinBox, QDial, QDateEdit,  etc.

Miscellaneous

PyQt has a special (and popular) tool called Qt designer which provides you with an GUI editor that you can use to create your own GUIs using Qt Widgets. It’s like a drag and drop editor where you don’t really have to code, rather just manipulate the widgets and their placement in the window.

Widget Comparison

Below are comparisons between three widgets that both GUI libraries have in common. I picked the three that showed the greatest difference.

Comparison between the QLineEdit and Entrybox.

PyQt vs Tkinter Input

Button Comparison (Biggest difference is here in my opinion).

PyQt vs Tkinter Button

Comparison between QComboBox and ComboBox.

PyQt vs Tkinter Combo

In can be a bit hard to tell the difference by simply comparing widgets individually like this. Ideally, you should try out both. You’ll understand the difference real quick then.

PyQt’s widgets are more interactive, such as the button glowing blue when the cursor is over it. You can only tell such a thing when actually using the GUI for yourself, so it’s best to actually run code for yourself. It’s these little differences that combined, end up making a big difference.

Code Comparision

Just for the sake of it, we decided to throw in a code comparison as well. The code below will create the same GUI with the same widgets. Its purpose is simple. There is an introductory label, a entry field which takes input and there are two buttons, one which prints the user input and the other closes the application.

It’s a fairly simple GUI application that any beginner might make. The code should be easy enough for you to follow even if you don’t know anything about either library.

Tkinter

Python
from tkinter import *

def display():
    print(my_entry.get())

def quit_window():
    root.destroy()
    sys.exit()

root = Tk()
root.geometry('300x300')

my_label = Label(root, text = "Tkinter GUI Application")
my_label.pack(pady = 10)

my_entry = Entry(root)
my_entry.pack(pady = 20)

my_button = Button(root, text = "Print", command = display, width = 10)
my_button.pack(pady = 10)

my_button2 = Button(root, text = "Quit", command = quit_window, width = 10)
my_button2.pack(pady = 10)

root.mainloop()

Tkinter GUI Example

PyQt5

Python
from PyQt5.QtWidgets import *
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys

def display():
    print(line_edit.text())

def quit_window():
    window.close()
    
app = QApplication(sys.argv)
window = QMainWindow()
window.setGeometry(400,400,300,300)
window.setWindowTitle("CodersLegacy")

label = QLabel(window)
label.setText("PyQt5 GUI Application")
label.adjustSize()
label.move(90, 30)

line_edit = QLineEdit(window)
line_edit.move(100, 70)

button = QPushButton(window)
button.setText("Print")
button.clicked.connect(display)
button.move(100, 130)

button2 = QPushButton(window)
button2.setText("Quit")
button2.clicked.connect(quit_window)
button2.move(100, 170)

window.show()
sys.exit(app.exec_())

PyQt GUI Example

Hopefully, the comparisons and descriptions we showed you today have helped you decide the answer to the PyQt vs Tkinter question.

Conclusion

So which one is the best GUI library? If I had to pick, it would be PyQt. Tkinter is good, and more than suitable for simple tasks, but PyQt just offers more overall in terms of widgets and looks.

If you’ve already learnt Tkinter and are comfortable with it, switching over isn’t really compulsory, just a recommended thing to do somewhere down the line. But if you haven’t begun either yet, I strongly recommend you start with PyQt.

This marks the end of the PyQt vs Tkinter article. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the article content can be asked in the comments section below.

This article was originally posted at https://coderslegacy.com/pyqt-vs-tkinter

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
GeneralTkinter has grid feature Pin
Andy J 20217-Mar-23 12:33
Andy J 20217-Mar-23 12:33 
QuestionPyQt/Pyside2 vs Tkinder Pin
Member 1126199112-Aug-20 2:29
professionalMember 1126199112-Aug-20 2:29 
SuggestionThere are more criteria that count ... Pin
Member 1237486411-Aug-20 11:08
Member 1237486411-Aug-20 11:08 
GeneralRe: There are more criteria that count ... Pin
CodingKnight11-Aug-20 20:29
CodingKnight11-Aug-20 20:29 
QuestionLeft out important side Pin
Paulus Koshivi10-Aug-20 23:48
Paulus Koshivi10-Aug-20 23:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.