问题
I found a very built-in and easy way to prompt a system-specific nice open file dialog:
import Tkinter
from tkFileDialog import askopenfilename
tk_root = Tkinter.Tk()
tk_root.withdraw()
result = askopenfilename(
filetypes=[("Foos", "*.png")],
)
However, this is way too heavy a dependency in terms of size. I'm packaging my app with py2exe and the app is 7 megabytes bigger for having to include Tkinter
. Surely there must be a simpler way to prompt a native file dialog that works on Windows, Mac, and Linux?
回答1:
There is a C library designed to perform this function, which could be wrapped in python.
https://github.com/mlabbe/nativefiledialog
Not sure what limitations the py2exe format imposes but I think this could be packaged into a pip wheel for example.
回答2:
If you're developing a pygame app, there's a project called Pygame Utilities which has cross-platform support for file dialogs, among many other things. It appears to be fairly lightweight.
Doesn't look to be very well documented, though. If you download the package, run the setup.py
file in the docs directory to generate the documentation.
来源:https://stackoverflow.com/questions/18326350/lightweight-cross-platform-way-to-prompt-for-a-file