Python Forum
TKinter restarting the mainloop when button pressed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TKinter restarting the mainloop when button pressed
#5
(Jan-25-2021, 07:13 AM)deanhystad Wrote: A GUI application runs all the time, though most of the time it is doing nothing but waiting for the user to click a mouse button or press a key. The windows or Linux desktop is a GUI. Do you stop and restart windows each time you want to run a program?

GUI's are event driven, and the user provides the events. I would expect your GUI to have some code that gets called when a button is pressed, and when the event handler code completes the GUI goes back to waiting for the next event. If you need to disable the button while the event is being processed, that is easily done. But the GUI is running all the time. No recursion. No stopping and restarting. Not even a loop as far as you are concerned.

If you already have code that does the complicated task you could write a very simple GUI application that runs your complicated application as a subprocess.


OKay but how do you suggest solving this problem? I still need to be able to stop a task if I want to? How would I rewrite my GUI then?

When the user presses the button, it executes a function which waits for another user input and etc but I must be able to return to its initial state "idle" state if I want to.

You say "and when the event handler code completes the GUI goes back to waiting for the next event" What if the event not complete I jsut want to cancel it? According to that logic, when I start some task in windows, I cannot cancel it unless I complete it but thats not true. Every windows task has an cross at the top right corner and you can close it whenever you want to even if you havent completed the task, closing the task does not shut down my computer, it just closes that task, and thats what I need
Reply


Messages In This Thread
RE: TKinter restarting the mainloop when button pressed - by zazas321 - Jan-25-2021, 07:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 1,027 Jan-16-2024, 06:44 PM
Last Post: rob101
  tkinter - touchscreen, push the button like click the mouse John64 5 877 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,906 May-25-2023, 07:37 PM
Last Post: deanhystad
  Can't get tkinter button to change color based on changes in data dford 4 3,450 Feb-13-2022, 01:57 PM
Last Post: dford
  Creating a function interrupt button tkinter AnotherSam 2 5,573 Oct-07-2021, 02:56 PM
Last Post: AnotherSam
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 5,052 Oct-01-2021, 05:00 PM
Last Post: Yoriz
  tkinter showing image in button rwahdan 3 5,663 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  tkinter button image Nick_tkinter 4 4,089 Mar-04-2021, 11:33 PM
Last Post: deanhystad
  tkinter python button position problem Nick_tkinter 3 3,585 Jan-31-2021, 05:15 AM
Last Post: deanhystad
  tkinter touchscreen scrolling - button press makes unwanted scrolling nanok66 1 4,030 Dec-28-2020, 10:00 PM
Last Post: nanok66

Forum Jump:

User Panel Messages

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