Python 的 JFileChooser?

发布于 2024-07-10 19:50:03 字数 151 浏览 5 评论 0原文

我想知道是否有类似于 Java 的 JFileChooser for Python 的东西?

JFileChooser 是一个用于选择文件的图形前端。

最好是 Python 已有的东西。 也许与 Tkinter 一起。

I was wondering if there is something similar to Java's JFileChooser for Python?

JFileChooser is a graphical front end to choose a file.

Preferably something that is already with Python. Maybe with Tkinter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

幸福丶如此 2024-07-17 19:50:03

wxPython (www.wxpython.org) 提供了 wx.FileDialog 类,它将在任何受支持的平台(Mac、Linux 或 Windows)上为您提供本机文件选择对话框。

wxPython (www.wxpython.org) provides the wx.FileDialog class which will give you a native file selection dialog on any of the supported platforms (Mac, Linux or Windows).

尬尬 2024-07-17 19:50:03

我发现的最简单的方法(使用 PyGTK 和 Kiwi):

from kiwi.ui.dialogs import open as open_dialog

chosen_path = open_dialog('Select a file', folder='/start/folder')

if chosen_path is not None:
    # do something ...

Easiest way I ever found to do this (using PyGTK and Kiwi):

from kiwi.ui.dialogs import open as open_dialog

chosen_path = open_dialog('Select a file', folder='/start/folder')

if chosen_path is not None:
    # do something ...
幸福还没到 2024-07-17 19:50:03

对于不需要 wxPython 并坚持使用标准 Python 库的东西,您可以使用 tkFileDialog.askopenfilename() 方法:

#!/usr/bin/python

from Tkinter import *
from tkFileDialog import askopenfilename

root = Tk()
root.withdraw()
print askopenfilename()

For something that doesn't require wxPython and sticks with the standard Python libs, you can use the tkFileDialog.askopenfilename() method:

#!/usr/bin/python

from Tkinter import *
from tkFileDialog import askopenfilename

root = Tk()
root.withdraw()
print askopenfilename()
戏蝶舞 2024-07-17 19:50:03

这取决于您的窗口工具包。 wxWidgets提供了wxFileDialog

That would depend on your windowing toolkit. wxWidgets provides the wxFileDialog.

因为看清所以看轻 2024-07-17 19:50:03

对于 python 3,您正在寻找的是 tkinter.filedialog 以及它附带的所有内容。 这是一个简短的程序,它打开并打印用户通过askopenfilename 选择的TXT 文件:

from tkinter import *
from tkinter.filedialog import askopenfilename

root = Tk()
root.withdraw()
root.update()
pathString = askopenfilename(filetypes=[("Text files","*.txt")])
if pathString:
    openFile = open(pathString, 'r')
    fileString = openFile.read()
    print(fileString)
root.destroy()

输出是所选文件中的任何内容。

For python 3 what you're looking for is tkinter.filedialog, and all that comes with it. Here's a short program that opens and then prints a TXT file of the user's choosing via askopenfilename:

from tkinter import *
from tkinter.filedialog import askopenfilename

root = Tk()
root.withdraw()
root.update()
pathString = askopenfilename(filetypes=[("Text files","*.txt")])
if pathString:
    openFile = open(pathString, 'r')
    fileString = openFile.read()
    print(fileString)
root.destroy()

Output is whatever is in the selected file.

陌伤浅笑 2024-07-17 19:50:03

也许您想看看 Jython。

Maybe you would like to take a look at Jython.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文