本文介绍了使用简单的对话框在 Python 中选择文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的 Python 控制台应用程序中获取文件路径作为输入.
I would like to get file path as input in my Python console application.
目前我只能在控制台中要求完整路径作为输入.
Currently I can only ask for full path as an input in the console.
有没有办法触发一个简单的用户界面,让用户可以选择文件而不是输入完整路径?
Is there a way to trigger a simple user interface where users can select file instead of typing the full path?
推荐答案
使用 tkinter 怎么样?
How about using tkinter?
from Tkinter import Tk # from tkinter import Tk for Python 3.x
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)
完成!
这篇关于使用简单的对话框在 Python 中选择文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!