使用简单对话框在Python中选择文件

2024-04-25 21:18:47 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
3条回答

使用EasyGui(由0.96版的pydocepydoc生成的文档):

import easygui
print(easygui.fileopenbox())

要安装:

pip install easygui

演示:

import easygui
easygui.egdemo()

用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)

完成!

Python3.x版本的Etaoin完整答案:

from tkinter.filedialog import askopenfilename
filename = askopenfilename()

相关问题 更多 >