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

这篇具有很好参考价值的文章主要介绍了Python 简易图形界面库easygui 对话框大全。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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

目录

​编辑

easygui

安装

导入

对话框

1. 消息框 msgbox

2. 确认框 ccbox

3. 布尔框 boolbox

4. 是否框 ynbox

5. 选择框 choicebox

6. 整数输入框 integerbox

7. 按钮选择框 buttonbox

8. 单行文本框 enterbox

9. 多行文本框 textbox


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种对话框样式。


对话框

1. 消息框 msgbox

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

    The ``msgbox()`` function displays a text message and offers an OK button. The message text appears in the center of the window, the title text appears in the title bar, and you can replace the "OK" default text on the button.
    :param str msg: the msg to be displayed
    :param str title: the window title
    :param str ok_button: text to show in the button
    :param str image: Filename of image to display
    :param tk_widget root: Top-level Tk widget

    :return: the text of the ok_button

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

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

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

2. 确认框 ccbox

ccbox(msg='Shall I continue?', title=' ', choices=('C[o]ntinue', 'C[a]ncel'), image=None, default_choice='Continue', cancel_choice='Cancel')

The ``ccbox()`` function offers a choice of Continue and Cancel, and returns either True (for continue) or False (for cancel).
    :param str msg: the msg to be displayed
    :param str title: the window title
    :param list choices: a list or tuple of the choices to be displayed
    :param str image: Filename of image to display
    :param str default_choice: The choice you want highlighted when the gui appears
    :param str cancel_choice: If the user presses the 'X' close, which button should be pressed

    :return: True if 'Continue' or dialog is cancelled, False if 'Cancel'

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

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

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

3. 布尔框 boolbox

boolbox(msg='Shall I continue?', title=' ', choices=('[T]rue', '[F]alse'), image=None, default_choice='[T]rue', cancel_choice='[F]alse')

    The ``boolbox()`` (boolean box) displays two buttons. Returns returns ``True`` if the first button is chosen. Otherwise returns ``False``.

    :param str msg: The message shown in the center of the dialog window.
    :param str title: The window title text.
    :param list choices: A list or tuple of strings for the buttons' text.
    :param str image: The filename of an image to display in the dialog window.
    :param str default_choice: The text of the default selected button.
    :param str cancel_choice: If the user presses the 'X' close, which button should be pressed

    :return: `True` if first button pressed or dialog is cancelled, `False` if second button is pressed.

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

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

与msgbox的联用,代码如下: 

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.')

4. 是否框 ynbox

ynbox(msg='Shall I continue?', title=' ', choices=('[<F1>]Yes', '[<F2>]No'), image=None, default_choice='[<F1>]Yes', cancel_choice='[<F2>]No')

    :param msg: the msg to be displayed
    :type msg: str
    :param str title: the window title
    :param list choices: a list or tuple of the choices to be displayed
    :param str image: Filename of image to display
    :param str default_choice: The choice you want highlighted when the gui appears
    :param str cancel_choice: If the user presses the 'X' close, which button should be pressed

    :return: True if 'Yes' or dialog is cancelled, False if 'No'

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

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

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.')

5. 选择框 choicebox

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

    The ``choicebox()`` provides a list of choices in a list box to choose from. The choices are specified in a sequence (a tuple or a list).

    :param str msg: the msg to be displayed
    :param str title: the window title
    :param list choices: a list or tuple of the choices to be displayed
    :param preselect: Which item, if any are preselected when dialog appears

    :return: A string of the selected choice or None if cancelled

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

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

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。


6. 整数输入框 integerbox

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

    Show a box in which a user can enter an integer.
    In addition to arguments for msg and title, this function accepts integer arguments for "default", "lowerbound", and "upperbound".
    The default, lowerbound, or upperbound may be None.
    When the user enters some text, the text is checked to verify that it can be converted to an integer between the lowerbound and upperbound.
    If it can be, the integer (not the text) is returned.
    If it cannot, then an error msg is displayed, and the integerbox is redisplayed.
    If the user cancels the operation, None is returned.

    :param str msg: the msg to be displayed
    :param str title: the window title
    :param int default: The default value to return
    :param int lowerbound: The lower-most value allowed
    :param int upperbound: The upper-most value allowed
    :param str image: Filename of image to display
    :param tk_widget root: Top-level Tk widget
    :return: the integer value entered by the user

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

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

如果可以,则返回整数(而不是文本)。
如果不能,则会显示一条错误消息,并重新显示integebox。
如果用户取消操作,则返回None。

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

import easygui
result = easygui.integerbox('请输入一个整数:')
print(result)

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

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

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


7. 按钮选择框 buttonbox

buttonbox(msg='', title=' ', choices=('Button[1]', 'Button[2]', 'Button[3]'), image=None, images=None, default_choice=None, cancel_choice=None, callback=None, run=True)

    Display a message, a title, an image, and a set of buttons.
    The buttons are defined by the members of the choices argument.

    :param str msg: the msg to be displayed
    :param str title: the window title
    :param list choices: a list or tuple of the choices to be displayed
    :param str image: (Only here for backward compatibility)
    :param str images: Filename of image or iterable or iteratable of iterable to display
    :param str default_choice: The choice you want highlighted when the gui appears

    :return: the text of the button that the user selected

显示多个按钮,按钮由参数choices的元组来定义,按钮的个数取决于元组的元素个数。

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

import easygui as eg
eg.buttonbox(msg='请选择:', title='自定义确认框', choices=('浏览...', '确定', '取消'), image=None, images=None, default_choice="确定", cancel_choice=None, callback=None, run=True)

8. 单行文本框 enterbox

enterbox(msg='Enter something.', title=' ', default='', strip=True, image=None, root=None)

    Show a box in which a user can enter some text.
    You may optionally specify some default text, which will appear in the nterbox when it is displayed.

    :param str msg: the msg to be displayed.
    :param str title: the window title
    :param str default: value returned if user does not change it
    :param bool strip: If True, the return value will have its whitespace stripped before being returned
    :return: the text that the user entered, or None if they cancel the operation.

显示一个框,用户可以在其中输入一些文本。您可以选择指定一些默认文本显示时显示在对话框中,如下图:

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

import easygui as eg
reply = eg.enterbox('请输入车牌号:','单行文本框', default='例如:苏ENH905')
if reply:
    eg.msgbox(f'你的输入为:{reply}')
else:
    eg.msgbox('输入为空,或者点了取消Cancel')

9. 多行文本框 textbox

textbox(msg='', title=' ', text='', codebox=False, callback=None, run=True)

Displays a dialog box with a large, multi-line text box, and returns the entered text as a string. The message text is displayed in a proportional font and wraps.

    Parameters
    ----------
    msg : string
        text displayed in the message area (instructions...)
    title : str
        the window title
    text: str, list or tuple
        text displayed in textAreas (editable)
    codebox: bool
        if True, don't wrap and width is set to 80 chars
    callback: function
        if set, this function will be called when OK is pressed
    run: bool
        if True, a box object will be created and returned, but not run

    Returns
    -------
    None
        If cancel is pressed
    str
        If OK is pressed returns the contents of textArea

 显示一个带有多行文本框的对话框,并将输入的文本作为字符串返回。例如:

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

import easygui as eg
txt = '''一、基本信息
  姓名:XX
  性别:X
  年龄:X
  婚姻状况:XX
  毕业院校:XX
  联系电话:XXXXXXXXXXX

二、求职意向
  意向岗位:XXXX
  证书:XXX
  薪资要求:面议
  工作能力及专长:本人有一定的......。

三、工作经历
  XXXX年X月~XXXX年X月,......。
  XXXX年X月~XXXX年X月,......。

四、自我评价
  本人对工作......'''
reply = eg.textbox(msg='请按以下模板输入你的简历:', title='简历', text=txt, codebox=False, callback=None, run=True)

print(reply)

待续......文章来源地址https://www.toymoban.com/news/detail-760495.html

到了这里,关于Python 简易图形界面库easygui 对话框大全的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • MFC基于对话框——仿照Windows计算器制作C++简易计算器

    目录 一、界面设计 二、设置成员变量 三、初始化成员变量  四、初始化对话框 ​五、添加控件代码 1.各个数字的代码(0~9) 2.清除功能的代码 3.退格功能的代码 4.加减乘除功能的代码 5.小数点功能的代码 6.正负号功能的代码 7.等于功能的代码 六、源码领取方式 制作好之后

    2024年02月05日
    浏览(44)
  • WPF HandyControl 界面交互反馈:对话框+加载框+列表选择

    我学了HandyControl的基础使用,但是发现HandyControl 封装了基础的消息提示,但是没有封装基础的交互逻辑。可能是因为我写了Uniapp,我知道封装了基础的交互其实一般就够用了。 Uniapp 界面交互反馈 我现在觉得,代码要低耦合一点,每个模块都纯粹一点,这一次我就不添加Nl

    2024年01月19日
    浏览(30)
  • 【pyqt5界面化工具开发-8】窗口开发-QDialog对话框

    目录 一、调用父类的菜单 二、添加更多的布局在对话框内 和前面Qwedget一样的结构(不做过多介绍) 可以参考代码中的注释 这和前面讲的Qwedget窗口布局基本上一样了 运行结果:

    2024年02月11日
    浏览(35)
  • .net-----Windows 窗体应用程序包括控件,对话框,多重窗体,绘制图形,菜单和工具栏

    Windows窗体应用程序概述;  使用Visual Studio开发Windows窗体应用程序;  窗体和控件概述;  使用常用Windows窗体控件;  通用对话框;  菜单和工具栏;  多重窗体;  多文档界面;  绘制图形 Windows窗体应用程序是运行在用户计算机本地的基于Windows的应用程序,

    2024年02月04日
    浏览(48)
  • Avalonia中用FluentAvalonia+DialogHost.Avalonia实现界面弹窗和对话框

    本文是项目中关于 弹窗界面 设计的技术分享,通过 FluentAvalonia + DialogHost.Avalonia 开源nuget包来实现项目中需要 弹框显示的界面 和所有的 对话框 的展示。 效果如下: 本项目是基于Avalonia的GPT的AI会话项目。采用的是最新稳定版本 11.0.0-rc1.1 。希望通过该项目了解和学习Avalon

    2024年02月16日
    浏览(42)
  • 计算机图形学实验——利用MFC对话框实现多边形绘制与填充(扫描线填充算法)附源码

    内容概括: 利用基于对话框的MFC项目 实现鼠标点击绘制多边形 实现扫描线算法填充多边形 源码见Yushan-Ji/ComputerGraphics: ECNU2023秋 计算机图形学课程实验代码 (github.com) 通过鼠标交互输入多边形 对各种多边形进行填充,包括边界自交的情况 利用 OnLButtonDown 和 OnRButtonDown 函数,

    2024年02月04日
    浏览(45)
  • Python Qt6快速入门-自定义对话框和标准对话框

    对话框是有用的 GUI 组件,可以与用户进行交流(因此得名对话框)。 它们通常用于文件打开/保存、设置、首选项或不适合应用程序主 UI 的功能。 它们是位于主应用程序前面的小模态(或阻塞)窗口,直到它们被关闭。 Qt 为最常见的用例提供

    2024年02月03日
    浏览(37)
  • 微信小程序开发系列(二十九)·界面交互API·loading 提示框、showModal模态对话框、showToast消息提示框

    目录 1.  loading 提示框 1. 1  wx.showLoading()显示loading提示框 1.2  wx.hideLoading()关闭 loading 提示框 2.  showModal 模态对话框 3.  showToast 消息提示框         小程序提供了一些用于界面交互的 API,例如:loading 提示框、消息提示框、模态对话框等 API。 loading 提示框常配合网络请

    2024年03月25日
    浏览(32)
  • QT调用不同UI界面响应,对话框跳转到主页面UI,用信号与槽传递信息,两级信号传递

    在MainWindow界面有一个按键”新建”,点击后需要生成一个输入对话框,实例用到了processDialog类对象。 我新建一行数据完成后,需要更新MainWindow表格的视图,此时就需要调用写在MainWIndow下的函数MainWindow::showProcess(vectorPCB* readyQueue) 但是如果实例化一个MainWidow对象,此时修改的

    2024年02月12日
    浏览(33)
  • Python 的Tkinter包系列之四:对话框

    对话框是计算机用户和计算机程序之间进行交互的重要手段。对话框是大多数现代GUI应用程序不可或缺的一部分。 Tkinter提供了这些对话框子模块: 消息框messagebox,由tkinter.messagebox模块提供 tkinter.messagebox --- Tkinter 消息提示 — Python 3.10.8 文档 文件选择对话框filedialog,由tki

    2024年02月04日
    浏览(34)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包