使用简单的Dialog在Python中选择一个文件 [英] Choosing a file in Python with simple Dialog

查看:292
本文介绍了使用简单的Dialog在Python中选择一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用最简单的库来选择本地目录中的文件。

I would like to use the simplest library to choose a file in local directories.

我的程序与一个花哨的用户界面无关。它可以从控制台获取所有的输入。我不希望用户进入控制台的整个路径。这只是我需要一个简单的用户界面。

My program has nothing to do with a fancy user interface. It can take all the input from the console. I don't want users to enter an entire path to the console. That's the only point I need a simple user interface.

您可以为此建议一个简单的跨平台python库吗?

Can you suggest me a simple, cross platform python library for this purpose?

推荐答案

如何使用Tkinter?

How about using Tkinter?

from Tkinter import Tk
from tkFileDialog 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)

完成!

这篇关于使用简单的Dialog在Python中选择一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆