python打开word文件求助
各位大神,我想用python的tkinter生成一个按钮,然后点击这个按钮可以打开我指定位置的word文件,就跟windows双击打开word那样,用来浏览word文件里面的内容。谢谢!{:5_106:} 直接在button的command事件函数里写
subprocess.Popen( 路径/文件名,shell=True)
就跟windows双击打开word那样
如果你有环境变量还可选打开方式 比如 subprocess.Popen( excel空格文件名,shell=True) import tkinter
from tkinter.filedialog import askopenfilename
import os
root = tkinter.Tk()
def openfile():
filepath = askopenfilename()
os.startfile(filepath)
button = tkinter.Button(text = "选择文件并打开", command = openfile)
button.pack()
root.mainloop()
页:
[1]