如何在tkinter中的按钮单击上运行python文件?
我有一个名为Home.py的python页面,其中包含一个名为查看报告的按钮。单击此按钮时,我希望执行另一个名为Reports.py的python页面。我使用tkinter开发了UI如何在tkinter中的按钮单击上运行python文件?,python,user-interface,tkinter,Python,User Interface,Tkinter,我有一个名为Home.py的python页面,其中包含一个名为查看报告的按钮。单击此按钮时,我希望执行另一个名为Reports.py的python页面。我使用tkinter开发了UI 提前表示感谢和问候 试试下面的代码。对我有用 def RunWrapper(): wrapper = ['python', 'Reports.py'] result1 = subprocess.Popen(wrapper, stdin=subprocess.PIPE, stderr=subproc
提前表示感谢和问候 试试下面的代码。对我有用
def RunWrapper():
wrapper = ['python', 'Reports.py']
result1 = subprocess.Popen(wrapper, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
out1, err1 = result1.communicate()
status_wrapper=out1.decode("utf-8")
tkinter.messagebox.showinfo("Execution of script is done")
Button.configure(pady="0",text='''Execute''',command=RunWrapper)
您可以使用来执行外部脚本。或者,如果主块位于外部脚本中的函数内部,请导入该函数并调用该函数。我已经尝试了子流程。但是它在我的系统中不起作用。你用
子进程做了什么尝试?发布test code.command=(“View Reports.py”)subprocess.Popen(command,shell=True)为什么不使用python
执行Reports.py
脚本?