Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.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
Python TKinter在新窗口中打开word文件_Python_Tkinter - Fatal编程技术网

Python TKinter在新窗口中打开word文件

Python TKinter在新窗口中打开word文件,python,tkinter,Python,Tkinter,我正在创建一个工具,根据技能筛选配置文件,然后最终打开一个word文档,其中包含所选配置文件的详细信息 我使用Tkinter显示每个过滤器的下拉菜单 下面是我的代码: from tkinter import * from pandas import * import os root=Tk() root.title('Skill Search Tool') def getProfile(): os.system("SelectedProfile.docx"

我正在创建一个工具,根据技能筛选配置文件,然后最终打开一个word文档,其中包含所选配置文件的详细信息

我使用Tkinter显示每个过滤器的下拉菜单

下面是我的代码:

from tkinter import *
from pandas import * 
import os

root=Tk()
root.title('Skill Search Tool')

def getProfile():
    
    os.system("SelectedProfile.docx")


ProfileGet= Button(root,text="Get Profile",command=getProfile())
ProfileGet.pack()


root.mainloop()
然而,当我点击按钮时,什么也没发生

有人能带我到这里吗

问候,,
Chinmay

当您将括号添加到末尾时,您正在调用函数
getProfiles
,这意味着它将在程序启动后立即运行,而您只需编写

ProfileGet=按钮(root,text=“Get Profile”,command=getProfile)

但是,如果将来希望将参数传递给函数,则可能需要使用lambda函数

ProfileGet= Button(root,text="Get Profile",command=lambda: getProfile(arg1,arg2))

您需要传递函数引用
command=getProfile
,而不是函数
command=getProfile()
的结果。如果您的平台是Windows,最好使用
os.startfile(…)
而不是
os.system(…)
。我正在使用Mac。我试图将代码从command=getProfile()更改为command=getProfile,并将函数定义更改为def getProfile():name=“SelectedProfile.docx”os.system(name),但现在我在单击按钮时遇到另一个错误。sh:SelectedProfile.docx:command未找到这是因为
os.system()
SelectedProfile.docx
视为命令。由于我不了解MacOS,您需要找到一种使用默认程序打开.docx的方法。可能会有帮助。