I have created 2 .py
files. i want that once the primary file closes, the second one opens using tkinter. This is a continuation of multiple commands for a tkinter button
.
The exit button functionality I have written is:-
from Backup_Server import GUI_Interface
def close_func():
os.kill(os.getpid(), signal.SIGINT)
GUI_Interface()
window.destroy()
server_socket.close()
if __name__ == "__main__":
exit_button = Button(topFrame, text='Quit', command=close_func)
GUI_Interface
is a function that I need to call after closing the existing .py
file. If I put GUI_Interface
as the first command for close_func()
, then it really does not go back to the 2nd step and never closes the existing .py
file.
And if I place GUI_Interface
in the end, it just closes the existing one and never opens the function of the new .py
file.
EDIT:-
Tried implementing the given solution but it just hangs both the primary and secondary Tkinter window:_
path_to_dir = os.getcwd()
print("path of file:;:\n", path_to_dir)
file_name = 'Backup_Server.py'
def close_func():
os.system(f'cd "{path_to_dir}"')
os.system(f'python {file_name}')
exit()
exit_button = Button(topFrame, text='Quit', command=close_func)
This is what I implemented as per the solution given.
So basically I have been able to solve this problem by creating another thread to GUI_Interface and then closing the existing file.