我想在我的Python控制台应用程序中获取文件路径作为输入。目前,我只能要求完整路径作为控制台中的输入。有没有一种触发简单用户界面的方法,用户可以在其中选择文件而不是键入完整路径?
3 回答

喵喵时光机
TA贡献1846条经验 获得超7个赞
使用tkinter怎么样?
from Tkinter import Tk
from tkinter.filedialog import askopenfilename
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filename)
做完了!

慕森王
TA贡献1777条经验 获得超3个赞
Etaoin答案的Python 3.x版本的完整性:
from tkinter.filedialog import askopenfilename
filename = askopenfilename()

墨色风雨
TA贡献1853条经验 获得超6个赞
使用EasyGui(由pydoc和epydoc生成的0.96版文档):
import easygui
print(easygui.fileopenbox())
安装:
pip install easygui
演示:
import easygui
easygui.egdemo()
添加回答
举报
0/150
提交
取消