What#39;s the simplest cross-platform way to pop up graphical dialogs in Python?(在 Python 中弹出图形对话框的最简单的跨平台方法是什么?)
问题描述
我想要在 Python 脚本中弹出简单对话框的最简单方法.理想情况下,解决方案是:
- 在 Windows、OS X、Gnome、KDE 上工作
 - 看起来像任何操作系统上的原生对话框
 - 需要最少的代码
 
要弹出一个简单的标准对话框,只需要最少的代码.本质上,您只是说弹出一个带有此文本的标准对话框",或弹出一个带有问题 x 的对话框并将响应输入变量 y".
这适用于在命令行上运行的简单脚本.我不想了解 GUI 框架,也不想设置启动 GUI 线程、注册事件处理程序、配置一些窗口属性、运行循环"等代码.我不想设置之后打开一个窗口或关闭窗口.我给它文本以放入窗口和/或按钮和/或复选框,它返回用户点击的内容.其他一切都应该自动处理.例如:
message_box('文件转换完成')对于带有确定"按钮的标准对话框,或
balloon_tip('文件转换完成')用于系统托盘弹出气球,或
format = button_box('你想要哪种文件格式?', 'JPG', 'PNG')他们按下两个按钮之一,然后 format 等于 'JPG',或者
response = text_query('你想给文件取什么名字?')在他们输入框并按确定后,response 现在等于 'bananas.txt'.无需其他代码.可怜的用户没有丑陋的命令行提示.
我将 Zenity 和 EasyGUI 列为示例答案,因为它们与我想要的相似,但并不完美.
[ 和 文档非常整洁.
之前,还有一个名为 EasyGuiTtk 的分支,遗憾的是不再可用.p>
I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would:
- Work on Windows, OS X, Gnome, KDE
 - Look like a native dialog on any OS
 - Require minimal code
 
To pop up a simple standard dialog should require only minimal code. Essentially you're just saying "Pop up a standard dialog with this text", or "Pop up a dialog with question x and feed response into variable y".
This is for simple scripts that would otherwise run on the command line. I don't want to know about GUI frameworks or have to set up code that says "start a GUI thread, register an event handler, configure some window properties, run a loop", etc. I don't want to have to set up a window or close the window afterward. I give it the text to put in the window and/or buttons and/or checkboxes, it returns what the user clicked on. Everything else should be taken care of automatically. For example:
message_box('File conversion complete')
for a standard dialog box with an "Ok" button, or
balloon_tip('File conversion complete')
for a system tray popup balloon, or
format = button_box('Which file format do you want?', 'JPG', 'PNG')
and they press one of the two buttons, and then format equals 'JPG', or
response = text_query('What would you like to name the file?')
and after they type in the box and press Ok, response now equals 'bananas.txt'.  No other code required.  No ugly command line prompts for the poor user.
I've listed Zenity and EasyGUI as example answers, since they're similar to what I want, but not perfect.
[Previously asked on Python Forum]
EasyGUI is a single file, and provides a simple way to work with Tkinter dialogs, but they're still ugly non-native Tkinter dialogs.
from easygui import msgbox
msgbox('Stuff')
It can easily be installed using:
$ sudo pip3 install --upgrade easygui
There is a GitHub repository and documentation is very neat.
Previously, there was also a fork called EasyGuiTtk, which unfortunately is no longer available.
这篇关于在 Python 中弹出图形对话框的最简单的跨平台方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Python 中弹出图形对话框的最简单的跨平台方法是什么?
				
        
 
            
        基础教程推荐
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
 - 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
 - 修改列表中的数据帧不起作用 2022-01-01
 - 在Python中从Azure BLOB存储中读取文件 2022-01-01
 - PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
 - PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
 - 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
 - 求两个直方图的卷积 2022-01-01
 - 包装空间模型 2022-01-01
 - Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				