Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter first or PyQt?

I'm trying to solidify my python knowledge by doing some gui development, should I try Tkinter or jump directly to PyQT for better IDE support?

like image 918
user3533659 Avatar asked Oct 20 '25 21:10

user3533659


2 Answers

If your main goal is to solidify your python knowledge, I would recommend Tkinter. It's simpler and it's already installed with Python.

If you want to build complex applications, I recommend PyQt, which is way more powerful.

like image 194
Amaury Medeiros Avatar answered Oct 23 '25 11:10

Amaury Medeiros


I have found a big difference between PyQt5 and Tkinter in long-running loops and dealing with the GUI freezing.

In both Tkinger and PyQt5, the GUI will freeze during long loops because the GUI update procedures aren't being called. To fix this in Tkinter I add this code:

Tkinter Solution

def update_app():
    root_winwod.update_idletasks()
    root_winwod.update()

for x in range(10000):
    if x % 100 = 0: # Triggers after 100 iterations. You can change this for your needs.
        update_app()
    
    # The rest of your loop code here

PyQt5 Solution

For PyQt5 you could call QtCore.QCoreApplication.processEvents() but all the websites say not to do this. Instead, you have to create a subprocess, create multiprocess safe variables with multiprocessing.Manager(), make sure that you lock and unlock the variables as you access them, use subprocess.check_output() to try and catch errors in your subprocess, add a Qtimer() to update the UI on a regular interval, make sure that you kill the processes when the app exits and so on.

For simple apps, I would suggest running Tkinter. Running subprocesses is fine, it just takes a lot of additional coding and effort to make sure that you get everything right.

like image 42
mjj2u2 Avatar answered Oct 23 '25 12:10

mjj2u2



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!