简体   繁体   English

轻量级跨平台方式提示文件

[英]Lightweight cross-platform way to prompt for a file

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 . 我使用py2exe打包了我的应用程序,该应用程序必须包含Tkinter ,因此要大7兆字节 Surely there must be a simpler way to prompt a native file dialog that works on Windows, Mac, and Linux? 当然,必须有一种更简单的方法来提示可在Windows,Mac和Linux上运行的本机文件对话框吗?

There is a C library designed to perform this function, which could be wrapped in python. 有一个旨在执行此功能的C库,可以将其包装在python中。

https://github.com/mlabbe/nativefiledialog 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. 不确定py2exe格式有什么限制,但是我认为可以将其打包到例如pip wheel中。

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. 如果您正在开发pygame应用程序,则有一个名为Pygame Utilities的项目,该项目除其他外还具有对文件对话框的跨平台支持。 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. 如果下载软件包,请运行docs目录中的setup.py文件以生成文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM