I have the following python 2.7 snippet code from a much larger script.
def RefreshAction():
execfile("SatTracker.py")
def CloseWindow():
window.destroy()
button = tk.Frame(window)
button = tk.Button(text='Refresh Data', width=25,command=lambda:[CloseWindow(),RefreshAction()])
button.pack()
window.mainloop()
So my entire code produces a tkinter window with images, text and a button. Now the button is supposed to trigger the command to close the Tkinter window, then rerun the entire script, which it does just fine. When I click the refresh button again, something weird happens. The window doesn't close anymore, but the script still starts up, with this error though.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\envs\python2\lib\lib-tk\Tkinter.py", line 1541, in __call__
return self.func(*args)
File "SatTracker.py", line 294, in <lambda>
button = tk.Button(text='Refresh Data', width=25,command=lambda:[CloseWindow(),RefreshAction()])
File "C:/Users/Peter Kongstad/Dropbox/Geoscience/2. Masters/7. Semester/Delphini-1 - Software Part/GUI/Programming/SatTracker.py", line 291, in CloseWindow
window.destroy()
File "C:\ProgramData\Anaconda3\envs\python2\lib\lib-tk\Tkinter.py", line 1864, in destroy
self.tk.call('destroy', self._w)
TclError: can't invoke "destroy" command: application has been destroyed
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\envs\python2\lib\lib-tk\Tkinter.py", line 1541, in __call__
return self.func(*args)
File "C:/Users/Peter Kongstad/Dropbox/Geoscience/2. Masters/7. Semester/Delphini-1 - Software Part/GUI/Programming/SatTracker.py", line 294, in <lambda>
button = tk.Button(text='Refresh Data', width=25,command=lambda:[CloseWindow(),RefreshAction()])
File "C:/Users/Peter Kongstad/Dropbox/Geoscience/2. Masters/7. Semester/Delphini-1 - Software Part/GUI/Programming/SatTracker.py", line 288, in RefreshAction
execfile("SatTracker.py")
File "SatTracker.py", line 297, in <module>
window.mainloop()
File "C:\ProgramData\Anaconda3\envs\python2\lib\lib-tk\Tkinter.py", line 1129, in mainloop
self.tk.mainloop(n)
KeyboardInterrupt
Effectively stopping everything. Now I do not necessarily need it to close the old tkinter window, as long as when I click the button, the script runs again and starts updating the current window with the new updated data.
So either way to fix this is fine by me. Any suggestions?