最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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ù)”和“取消”選項(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.

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

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

當(dāng)用戶輸入一些文本時,會檢查文本以驗(yàn)證它是否可以轉(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('輸入為空,或者點(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

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

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注釋讓代碼更加的優(yōu)雅

    這樣寫python注釋讓代碼更加的優(yōu)雅

    任何編程語言都少不了注釋,Python當(dāng)然也不例外,下面這篇文章主要給大家介紹了關(guān)于如何寫python注釋,才能讓你的代碼更加的優(yōu)雅,需要的朋友可以參考下
    2021-06-06
  • matplotlib?3D模型繪制一朵小紅花

    matplotlib?3D模型繪制一朵小紅花

    這篇文章主要介紹了matplotlib?3D模型繪制一朵小紅花,代碼有趣也有一定的知識參考價值,需要的朋友可以參考文章內(nèi)容下去試試
    2022-02-02
  • python socket網(wǎng)絡(luò)編程之粘包問題詳解

    python socket網(wǎng)絡(luò)編程之粘包問題詳解

    這篇文章主要介紹了python socket網(wǎng)絡(luò)編程之粘包問題詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04
  • 一行Python3代碼實(shí)現(xiàn)解析地址信息

    一行Python3代碼實(shí)現(xiàn)解析地址信息

    在日常數(shù)據(jù)處理的過程中,有時候拿到手的是完整的地址信息,如果需要從地址信息中解析出相應(yīng)的各級行政單元名稱,方式有很多,而今天要介紹的方式只需要一行代碼即可快速實(shí)現(xiàn),快跟隨小編一起學(xué)習(xí)一下吧
    2022-05-05
  • Python數(shù)據(jù)持久化shelve模塊用法分析

    Python數(shù)據(jù)持久化shelve模塊用法分析

    這篇文章主要介紹了Python數(shù)據(jù)持久化shelve模塊用法,結(jié)合實(shí)例形式較為詳細(xì)的總結(jié)分析了shelve模塊的功能、原理及簡單使用方法,需要的朋友可以參考下
    2018-06-06
  • Python 編碼Basic Auth使用方法簡單實(shí)例

    Python 編碼Basic Auth使用方法簡單實(shí)例

    這篇文章主要介紹了 Python 編碼Basic Auth使用方法簡單實(shí)例的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • Django上傳excel表格并將數(shù)據(jù)寫入數(shù)據(jù)庫的詳細(xì)步驟

    Django上傳excel表格并將數(shù)據(jù)寫入數(shù)據(jù)庫的詳細(xì)步驟

    這篇文章主要介紹了Django上傳excel表格并將數(shù)據(jù)寫入數(shù)據(jù)庫,將文件上傳到服務(wù)器指定路徑,其實(shí)很簡單,本文分三個步驟給大家詳細(xì)介紹,需要的朋友可以參考下
    2022-06-06
  • 在pycharm中設(shè)置顯示行數(shù)的方法

    在pycharm中設(shè)置顯示行數(shù)的方法

    今天小編就為大家分享一篇在pycharm中設(shè)置顯示行數(shù)的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-01-01
  • Python虛擬環(huán)境庫virtualenvwrapper安裝及使用

    Python虛擬環(huán)境庫virtualenvwrapper安裝及使用

    這篇文章主要介紹了Python虛擬環(huán)境庫virtualenvwrapper安裝及使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-06-06
  • Python使用socket_TCP實(shí)現(xiàn)小文件下載功能

    Python使用socket_TCP實(shí)現(xiàn)小文件下載功能

    這篇文章主要介紹了Python使用socket_TCP實(shí)現(xiàn)小文件下載功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-10-10

最新評論

斗六市| 九龙坡区| 盘山县| 会同县| 新和县| 丰宁| 茌平县| 西盟| 桃源县| 商水县| 嘉义市| 徐汇区| 定安县| 东源县| 临猗县| 和田县| 土默特右旗| 兴和县| 沙湾县| 仙居县| 遂平县| 虹口区| 黎平县| 宾阳县| 获嘉县| 长宁区| 杨浦区| 虞城县| 松原市| 肥西县| 绥化市| 龙川县| 大化| 澄迈县| 阿瓦提县| 喀喇沁旗| 砀山县| 江达县| 大同市| 林西县| 罗源县|