Lightweight cross-platform way to prompt for a file

依然范特西╮ 提交于 2019-12-02 11:14:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!