退出主要.py文件时无法打开另一个.py文件 [英] Unable to open another .py file on exiting the primary .py file
问题描述
我已经创建了2个 .py
文件.我希望一旦主文件关闭,第二个文件就会使用tkinter打开.这是 tkinter按钮的多个命令的延续
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
是关闭现有 .py
文件后需要调用的函数.如果我将 GUI_Interface
用作 close_func()
的第一个命令,那么它实际上不会退回到第二步,也永远不会关闭现有的 .py 代码>文件.
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.
如果我将 GUI_Interface
放在最后,它只会关闭现有的一个,而永远不会打开新的 .py
文件的功能.
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.
-
尝试实现给定的解决方案,但它只是同时挂起了主Tkinter窗口和辅助Tkinter窗口:_
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.
推荐答案
基本上,我已经能够通过创建另一个GUI_Interface线程并关闭现有文件来解决此问题.
So basically I have been able to solve this problem by creating another thread to GUI_Interface and then closing the existing file.
这篇关于退出主要.py文件时无法打开另一个.py文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!