Python EasyGUI 调起文件选择窗口

更新日期: 2022-02-10 阅读次数: 3644 字数: 243 分类: Python

由于 opencv 做图像识别需要测试大量的图片样本,逐一比对效果,以方便调整参数及处理逻辑。 如果写死文件路径,每次换图片都需要改代码,非常不方便;也不利于代码管理。

所以,我需要能用 python 调起文件选择窗口,选择图片,然后返回文件路径。

EasyGUI

找到一个非常合适的库,EasyGUI。很容易拼错成 EasyUI。

EasyGUI is a module for very simple, very easy GUI programming in Python. EasyGUI is different from other GUI libraries in that EasyGUI is NOT event-driven. Instead, all GUI interactions are invoked by simple function calls.

https://github.com/robertlugg/easygui

大略看了一下这个库,除了能弹出文件选择窗口,还能弹出 confirm, alert 窗口,以及单选组件。 Tk 界面风格也不算太丑。

安装 EasyGUI

pip install easygui

调起文件选择窗口

Windows 10 上 Python 3.8 IDLE 测试:

>>> import easygui
>>> easygui.fileopenbox()
'D:\\vim-8.2.4316.tar.gz'

python 选择文件窗口

集成到 opencv 中

imgPath = easygui.fileopenbox()
img = cv2.imread(imgPath)  

参考

tags: OpenCV

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式