Tkinter Question

Post here if you need help with creating a Graphical User Interface in Python.

Tkinter Question

Postby Flexico » Mon Aug 15, 2016 8:37 pm

I'm using Tkinter to make a graphing-calculator-like program that plots various types of functions. However, the GUI completely freezes until all calculations are finished, and then shows the completed graph afterward. I'd like it to show the graph as it's being drawn, or at least show some kind of progress bar (as some graphs take several minutes to draw). Is there a command that updates the GUI before the focus returns to the main loop?

Did I explain that properly? I hope it's not confusing. :o
User avatar
Flexico
 
Posts: 8
Joined: Sun Oct 18, 2015 11:42 pm

Re: Tkinter Question

Postby Flexico » Mon Aug 15, 2016 10:01 pm

Also, is there a way to save a "canvas" module as an image? Preferably png.
User avatar
Flexico
 
Posts: 8
Joined: Sun Oct 18, 2015 11:42 pm

Re: Tkinter Question

Postby Ofnuts » Mon Aug 15, 2016 10:03 pm

This is expected. The UI can only be updated after the event is processed, and the event processing includes all your computation since this is all done in the same thread. This is fairly well explained here, together with possible solutions. But TkInter doesn't make it easy....
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987

Re: Tkinter Question

Postby Flexico » Tue Aug 16, 2016 12:56 am

Considering the headache I received while reading that page, I'm just going to tolerate the GUI freezing. Plus I found a way to make the program load faster, so yay! X3
User avatar
Flexico
 
Posts: 8
Joined: Sun Oct 18, 2015 11:42 pm

Re: Tkinter Question

Postby Flexico » Wed Aug 24, 2016 1:44 am

Ok, I spent an entire morning fiddling with callback structures (which are pretty cool but confusing) before stumbling across a comment that offers a single command that fixes everything:

[Tkinter window object].update()

Just run that line anywhere in your code and the GUI will update, and even allow you to change text fields and press buttons before the command is finished running. I'm surprised nobody else knew of this.
User avatar
Flexico
 
Posts: 8
Joined: Sun Oct 18, 2015 11:42 pm


Return to GUI

Who is online

Users browsing this forum: No registered users and 3 guests

cron