Python Forum
How to stop a tkinter function, without closing the window?
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to stop a tkinter function, without closing the window?
#1
So, I feel like this should be kind of a simple thing to do.  Yet, I am having so much troubel with it.  I have tinkered around with the after method, but it either doesn't ork, or runs VERY slow.  It also doesn't let me graph work  (I am graphing serial data with my GUI).

Then, sys.exit() only works in IDLE3. Otherwise, the "system" that exits is the whole GUI.

I am new. Not sure how to post code....  So, here is a bit of code:


****indents only messed up because of paste

This code is my "closing" function to "close" the other functions.....

   def restart (self):
        self.running = False
       self.ani = None
       os.system("sudo mkdir " + str(subfolder))
       
os.system("sudo mv /home/pi/Documents/* " + str(subfolder))
        print("stopthisnow")

       root.after_cancel (self.get_data)
       root.after_cancel(self.update_graph)
       
       #root.update_idletasks()
       
#self.after_cancel(self.after_id)
       #self.after_cancel(self.after_id2)

        #return None
Reply
#2
see .withdraw here :http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/toplevel.html
Reply
#3
.withdraw appears to close my window. I want the GUI to stay there, but just lose it's function. Then when buttons are clicked again, the function resumes.
Reply
#4
Read the docs! that's why I provided a link.
Quote: .withdraw()

Hides the window. Restore it with .deiconify() or .iconify().
Reply
#5
Are you running restart() in a separate thread? os.system will wait for the underlying system call to finish, so if that takes a long time, the whole gui will freeze while it runs (though that probably doesn't matter here, since you're just moving a folder).
Reply
#6
Larz60+, I will look into it again. I don't think I did the .deconify or .conify when I tried it.


nilamo:

restart() is not its separate thread. CODE SUMMARY:

def update_graph()

if statement
print("still running")
else:

self.restart()


def restart()

***stops all other functions without closing window
(right now, throws an error, but does just this. I don't feel good about it though...)

Everything is successful with the code except stopping the functions that are running without closing the window.

Does this make sense? I can post more of the code if need be.

Larz60+

I think the .withdraw and .deiconify thing will work if I get it to stop going through the def update_graph() statement. It keeps looping through that function, making it continuously loop through the restart() function and close and refresh window over and over when I use root.withdraw() and root.deiconify(). I am just placing these in the restart() function.

(Jun-29-2017, 11:53 AM)keakins Wrote: restart() is not its separate thread. CODE SUMMARY:
Sorry, it's its own function, but still within the same class where it needs called upon as "self.restart" Sorry, I am a beginner. Just learning as I go...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 471 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Using Tkinter inside function not working Ensaimadeta 5 4,990 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 828 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  [PyQt] PyQt5 window closing when trying to display a graph bianca 4 1,671 Aug-12-2023, 03:25 PM
Last Post: bianca
Exclamation [Tkinter] Error when closing the main window with destroy TomasSanchexx 1 763 Aug-06-2023, 01:54 AM
Last Post: deanhystad
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,662 May-25-2023, 07:37 PM
Last Post: deanhystad
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,897 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  Tkinter won't run my simple function AthertonH 6 3,823 May-03-2022, 02:33 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,911 Apr-16-2022, 04:04 PM
Last Post: DBox
  why my list changes to a string as I move to another window in tkinter? pymn 4 2,572 Feb-17-2022, 07:02 AM
Last Post: pymn

Forum Jump:

User Panel Messages

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