欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python簡(jiǎn)易圖形界面庫(kù)easygui對(duì)話框整理大全

 更新時(shí)間:2024年01月11日 09:58:10   作者:Hann?Yang  
這篇文章主要給大家介紹了關(guān)于Python簡(jiǎn)易圖形界面庫(kù)easygui對(duì)話框的相關(guān)資料,EasyGUI是一個(gè)用Python編寫(xiě)的非常簡(jiǎn)易的GUI編程模塊,文中通過(guò)代碼介紹的非常詳細(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種對(duì)話框樣式。

對(duì)話框

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ù)”和“取消”選項(xiàng),并返回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.

如果選擇了第一個(gè)按鈕,則返回“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

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

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”后點(diǎn)OK就把所選擇的項(xiàng)賦值給變量choice,點(diǎn)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

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

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

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

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

注:輸入整數(shù)超出上下限或輸入的不是一個(gè)整數(shù),返回一個(gè)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

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

import easygui as eg
eg.buttonbox(msg='請(qǐng)選擇:', 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.

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

import easygui as eg
reply = eg.enterbox('請(qǐng)輸入車(chē)牌號(hào):','單行文本框', default='例如:蘇ENH905')
if reply:
    eg.msgbox(f'你的輸入為:{reply}')
else:
    eg.msgbox('輸入為空,或者點(diǎn)了取消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

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

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

總結(jié)

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

相關(guān)文章

最新評(píng)論