Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在tkinter中的按钮单击上运行python文件?_Python_User Interface_Tkinter - Fatal编程技术网

如何在tkinter中的按钮单击上运行python文件?

如何在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

我有一个名为Home.py的python页面,其中包含一个名为查看报告的按钮。单击此按钮时,我希望执行另一个名为Reports.py的python页面。我使用tkinter开发了UI


提前表示感谢和问候

试试下面的代码。对我有用

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
脚本?