亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python簡易圖形界面庫easygui對話框整理大全

 更新時間:2024年01月11日 09:58:10   作者:Hann?Yang  
這篇文章主要給大家介紹了關(guān)于Python簡易圖形界面庫easygui對話框的相關(guān)資料,EasyGUI是一個用Python編寫的非常簡易的GUI編程模塊,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下

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

導(dǎo)入

>>> 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

顯示文本消息并提供“確定”按鈕。消息文本顯示在窗口的中心,標(biāo)題文本顯示在標(biāo)題欄中,可以替換按鈕上的“確定”默認(rèn)文本,例如:

easygui.msgbox("備份完成!", title="結(jié)束", ok_button="干得好!")

2. 確認(rèn)框 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'

提供了“繼續(xù)”和“取消”選項,并返回True(表示繼續(xù))或False(表示取消)。默認(rèn)的按鈕文本為:'Continue' 和 'Cancel',也可以使用按鈕文本自定義,例如: 

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

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”。

與msgbox的聯(lián)用,代碼如下: 

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”。

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

在列表框中提供了可供選擇的由元組或列表指定的選項列表。

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. 整數(shù)輸入框 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

顯示一個框,用戶可以在其中輸入整數(shù)。除了msg和title的參數(shù)外,此函數(shù)還接受“default”、“lowerbound”和“upperfound”的整數(shù)參數(shù)。默認(rèn)值、下限值或上限值可能為“None”。

當(dāng)用戶輸入一些文本時,會檢查文本以驗證它是否可以轉(zhuǎn)換為介于下限和上限之間的整數(shù)。

  • 如果可以,則返回整數(shù)(而不是文本)。
  • 如果不能,則會顯示一條錯誤消息,并重新顯示integebox。
  • 如果用戶取消操作,則返回None。

import easygui
result = easygui.integerbox('請輸入一個整數(shù):')
print(result)

注:輸入整數(shù)超出上下限或輸入的不是一個整數(shù),返回一個msgbox:

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

顯示多個按鈕,按鈕由參數(shù)choices的元組來定義,按鈕的個數(shù)取決于元組的元素個數(shù)。

import easygui as eg
eg.buttonbox(msg='請選擇:', title='自定義確認(rèn)框', 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.

顯示一個框,用戶可以在其中輸入一些文本。您可以選擇指定一些默認(rèn)文本顯示時顯示在對話框中,如下圖:

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

 顯示一個帶有多行文本框的對話框,并將輸入的文本作為字符串返回。例如:

import easygui as eg
txt = '''一、基本信息
  姓名:XX
  性別:X
  年齡:X
  婚姻狀況:XX
  畢業(yè)院校:XX
  聯(lián)系電話:XXXXXXXXXXX
二、求職意向
  意向崗位:XXXX
  證書:XXX
  薪資要求:面議
  工作能力及專長:本人有一定的......。
三、工作經(jīng)歷
  XXXX年X月~XXXX年X月,......。
  XXXX年X月~XXXX年X月,......。
四、自我評價
  本人對工作......'''
reply = eg.textbox(msg='請按以下模板輸入你的簡歷:', title='簡歷', text=txt, codebox=False, callback=None, run=True)
 
print(reply)

總結(jié)

到此這篇關(guān)于Python簡易圖形界面庫easygui對話框的文章就介紹到這了,更多相關(guān)Python圖形界面庫easygui對話框內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 使用python PIL庫實現(xiàn)簡單驗證碼的去噪方法步驟

    使用python PIL庫實現(xiàn)簡單驗證碼的去噪方法步驟

    這篇文章主要介紹了使用python PIL庫實現(xiàn)簡單驗證碼的去噪方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • Python中for循環(huán)和while循環(huán)的基本使用方法

    Python中for循環(huán)和while循環(huán)的基本使用方法

    這篇文章主要介紹了Python中for循環(huán)和while循環(huán)的基本使用方法,是Python入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下
    2015-08-08
  • 詳解Pandas如何高效對比處理DataFrame的兩列數(shù)據(jù)

    詳解Pandas如何高效對比處理DataFrame的兩列數(shù)據(jù)

    我們在用?pandas?處理數(shù)據(jù)的時候,經(jīng)常會遇到用其中一列數(shù)據(jù)替換另一列數(shù)據(jù)的場景。這一類的需求估計很多人都遇到,當(dāng)然還有其它更復(fù)雜的。解決這類需求的辦法有很多,這里我們來推薦幾個
    2022-09-09
  • Django 解決新建表刪除后無法重新創(chuàng)建等問題

    Django 解決新建表刪除后無法重新創(chuàng)建等問題

    這篇文章主要介紹了Django 解決新建表刪除后無法重新創(chuàng)建等問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-05-05
  • python一繪制元二次方程曲線的實例分析

    python一繪制元二次方程曲線的實例分析

    在本篇文章里小編給大家整理的是一篇關(guān)于python一繪制元二次方程曲線的實例分析內(nèi)容,有興趣的朋友們可以跟著學(xué)習(xí)參考下。
    2021-07-07
  • 在Django的視圖中使用form對象的方法

    在Django的視圖中使用form對象的方法

    這篇文章主要介紹了在Django的視圖中使用form對象的方法,Django是Python豐富多彩的開發(fā)框架中最具有人氣的一個,需要的朋友可以參考下
    2015-07-07
  • Python基礎(chǔ)教程之if判斷,while循環(huán),循環(huán)嵌套

    Python基礎(chǔ)教程之if判斷,while循環(huán),循環(huán)嵌套

    這篇文章主要介紹了Python基礎(chǔ)教程之if判斷,while循環(huán),循環(huán)嵌套 的相關(guān)知識,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-04-04
  • Django制作簡易注冊登錄系統(tǒng)的實現(xiàn)示例

    Django制作簡易注冊登錄系統(tǒng)的實現(xiàn)示例

    本文介紹了如何使用Django搭建一個簡易的注冊登錄系統(tǒng),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-11-11
  • numpy 返回函數(shù)的上三角矩陣實例

    numpy 返回函數(shù)的上三角矩陣實例

    今天小編就為大家分享一篇numpy 返回函數(shù)的上三角矩陣實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • python發(fā)送告警郵件腳本

    python發(fā)送告警郵件腳本

    這篇文章主要介紹了python發(fā)送告警郵件腳本的配置方法,zabbix通過python腳本發(fā)告警郵件,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-09-09

最新評論