user3533659
user3533659

Reputation: 41

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?

Upvotes: 4

Views: 3712

Answers (2)

mjj2u2
mjj2u2

Reputation: 39

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.

Upvotes: 2

Amaury Medeiros
Amaury Medeiros

Reputation: 2233

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.

Upvotes: 2

Related Questions