Python Forum

Full Version: How to stop a tkinter function, without closing the window?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
see .withdraw here :http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/toplevel.html
.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.
Read the docs! that's why I provided a link.
Quote: .withdraw()

Hides the window. Restore it with .deiconify() or .iconify().
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).
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...