Python Forum
GUI freezes while executing a callback funtion when a button is pressed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GUI freezes while executing a callback funtion when a button is pressed
#6
(Jul-08-2019, 10:22 PM)abi17124 Wrote: What I would like is to for the GUI to be running while the edit function executes instead of freezing, and also in the future, to pause/continue the editing at any given time with buttons I intend to add into the GUI.

You've run into the classic problem of trying to do a lot of CPU or wall-clock intensive operations. When your program begins to take so much of the processor that you "starve" your GUI of CPU cycles, it's then that you turn to Threads to get yourself out of the problem.

To get through this, you need to startup threads at places where your operations will block for a long time. This program is a demonstration of how to do that with PySimpleGUI:
https://repl.it/@PySimpleGUI/Threaded-fo...long-tasks

You can also run it there and see how it works. To use it just type in the number of seconds you want your function to take and press the button to start it. While that thread is "busy" doing work (sleeping) notice how you can continue to take input from the GUI and act on it.

There's little of your code that you need to change other than to start a thread instead of call a function. If you need to know when the operation completes, then communicate through a queue like in the demo.
Reply


Messages In This Thread
RE: GUI freezes while executing a callback funtion when a button is pressed - by FullOfHelp - Jul-10-2019, 12:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tkinter callback exception Ben123 2 538 Feb-17-2024, 06:03 PM
Last Post: deanhystad
  TKinter restarting the mainloop when button pressed zazas321 7 16,304 Jan-26-2021, 06:38 AM
Last Post: zazas321
  [PyQt] SSH port forwarding and connection to SQL Server in separate threads freezes jan_pips 25 10,772 Dec-03-2019, 04:28 PM
Last Post: Denni
  [Tkinter] How to bind an event when enter is pressed on a Entry control? Michael4 4 3,948 Aug-29-2019, 10:11 PM
Last Post: Michael4
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 4,997 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  [matpltlib]Basic question about callback function schniefen 3 3,202 May-20-2019, 09:47 PM
Last Post: Yoriz
  [Kivy] Chagne a button's function after its first pressed TheStraying11 2 5,068 Feb-17-2019, 06:16 PM
Last Post: Yoriz
  Unable to return value from callback function of a button in Python Tkinter nilaybnrj 4 20,777 Aug-05-2018, 11:01 PM
Last Post: woooee
  [Tkinter] tkinter freezes by clicking button Zatox11 33 25,676 Apr-10-2018, 09:03 AM
Last Post: Zatox11
  Running telnet loop freezes GUI reedhallen 1 3,440 Jan-27-2018, 10:24 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020