Python 简易图形界面库easygui 对话框大全

easygui

安装

C:\> pip install easygui

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple

Collecting easygui

Using cached https://pypi.tuna.tsinghua.edu.cn/packages/8e/a7/b276ff776533b423710a285c8168b52551cb2ab0855443131fdc7fd8c16f/easygui-0.98.3-py2.py3-none-any.whl (92 kB)

Installing collected packages: easygui

Successfully installed easygui-0.98.3

导入

>>> import easygui

>>> easygui.all

'buttonbox', 'diropenbox', 'fileopenbox', 'filesavebox', 'textbox', 'ynbox', 'ccbox', 'boolbox', 'indexbox', 'msgbox', 'integerbox', 'multenterbox', 'enterbox', 'exceptionbox', 'choicebox', 'codebox', 'passwordbox', 'multpasswordbox', 'multchoicebox', 'EgStore', 'eg_version', 'egversion', 'abouteasygui', 'egdemo'

由以上列表,可以看到easygui共包含了19种对话框样式。


对话框

消息框 msgbox

msgbox(msg='(Your message goes here)', title=' ', ok_button='OK', image=None, root=None)

显示文本消息并提供"确定"按钮。消息文本显示在窗口的中心,标题文本显示在标题栏中,可以替换按钮上的"确定"默认文本,例如:

easygui.msgbox("备份完成!", title="结束", ok_button="干得好!")

确认框 ccbox

ccbox(msg='Shall I continue?', title=' ', choices=('Continue', 'Cancel'), image=None, default_choice='Continue', cancel_choice='Cancel')

提供了"继续"和"取消"选项,并返回True(表示继续)或False(表示取消)。默认的按钮文本为:'Continue' 和 'Cancel',也可以使用按钮文本自定义,例如:

easygui.ccbox(msg, title, choices=('退出E','取消C'))

布尔框 boolbox

如果选择了第一个按钮,则返回"True"。否则返回"False"。

boolbox(msg='Shall I continue?', title=' ', choices=('True', 'False'), image=None, default_choice='True', cancel_choice='False')

与msgbox的联用,代码如下:

python 复制代码
import easygui
message = "What do they say?"
title = "Romantic Question"
if easygui.boolbox(message, title, ["They love me", "They love me not"]):
    easygui.msgbox('You should send them flowers.')
else:
    easygui.msgbox('It was not meant to be.')

是否框 ynbox

ynbox(msg='Shall I continue?', title=' ', choices=('\Yes', '\No'), image=None, default_choice='\Yes', cancel_choice='\No')

提供了Yes和No的选择,并返回"True"或"False"。

python 复制代码
import easygui
result = easygui.ynbox('Is a hot dog a sandwich?', 'Hot Dog Question')
if result == True:
    easygui.msgbox('That is an interesting answer.')
else:
    easygui.msgbox('Well, that is your opinion.')

选择框 choicebox

choicebox(msg='Pick an item', title='', choices=None, preselect=0, callback=None, run=True)

在列表框中提供了可供选择的由元组或列表指定的选项列表。

python 复制代码
import easygui
msg ="What is your favorite flavor?"
title = "Ice Cream Survey"
choices = ["Vanilla", "Chocolate", "Strawberry", "Coffee Latte"]
choice = easygui.choicebox(msg, title, choices)  # choice is a string
print(choice)

注:选择"Chocolate"后点OK就把所选择的项赋值给变量choice,点Cancel则返回None。


整数输入框 integerbox

integerbox(msg='', title=' ', default=None, lowerbound=0, upperbound=99, image=None, root=None)

显示一个框,用户可以在其中输入整数。除了msg和title的参数外,此函数还接受"default"、"lowerbound"和"upperfound"的整数参数。默认值、下限值或上限值可能为"None"。

当用户输入一些文本时,会检查文本以验证它是否可以转换为介于下限和上限之间的整数。

如果可以,则返回整数(而不是文本)。

如果不能,则会显示一条错误消息,并重新显示integebox。

如果用户取消操作,则返回None。

python 复制代码
import easygui
result = easygui.integerbox('请输入一个整数:')
print(result)

注:输入整数超出上下限或输入的不是一个整数,返回一个msgbox:


还有好多个对话框样式,有空再一一补上。

相关推荐
默_笙2 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
qq_426003962 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫2 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技2 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读2 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
只睡四小时2 天前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
奇思妙想聪明勤奋的小羊2 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
lpfasd1232 天前
2026年第38周GitHub趋势周报
python·科技·github
IZero072 天前
Jev 与 Laya
python·语言模型