easygui
Install
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
>>> 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']
From the above list, you can see that easygui contains a total of 19 dialog styles.
dialog box
message box msgbox
msgbox(msg='(Your message goes here)', title=' ', ok_button='OK', image=None, root=None)
Displays a text message and provides an OK button. The message text is displayed in the center of the window and the title text is displayed in the title bar, which can replace the "OK" default text on the button, for example:
easygui.msgbox("Backup completed!", title="End", ok_button="Good job!")
Confirmation box ccbox
ccbox(msg='Shall I continue?', title=' ', choices=('C[o]ntinue', 'C[a]ncel'), image=None, default_choice='Continue', cancel_choice='Cancel')
"Continue" and "Cancel" options are provided and return True (for continuing) or False (for cancelling). The default button text is: 'Continue' and 'Cancel', you can also customize the button text, for example:
easygui.ccbox(msg, title, choices=('Exit[E]','Cancel[C]'))
Boolean box boolbox
Returns "True" if the first button is selected. Otherwise returns "False".
boolbox(msg='Shall I continue?', title=' ', choices=('[T]rue', '[F]alse'), image=None, default_choice='[T]rue', cancel_choice='[F]alse')
For use with msgbox, the code is as follows:
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.')
Whether to box ynbox
ynbox(msg='Shall I continue?', title=' ', choices=('[<F1>]Yes', '[<F2>]No'), image=None, default_choice='[<F1>]Yes', cancel_choice='[<F2>]No')
Provides a choice of Yes and No, and returns "True" or "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.')
choiceboxchoicebox
choicebox(msg='Pick an item', title='', choices=None, preselect=0, callback=None, run=True)
A list box provides a list of options, specified by a tuple or list, from which to choose.
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)
Note: After selecting "Chocolate" and clicking OK, the selected item will be assigned to the variable choice. Clicking Cancel will return None.
integer input box integerbox
integerbox(msg='', title=' ', default=None, lowerbound=0, upperbound=99, image=None, root=None)
Displays a box where the user can enter an integer. In addition to the parameters msg and title, this function also accepts integer parameters "default", "lowerbound" and "upperfound". The default, lower or upper limit value may be "None".
When the user enters some text, the text is checked to verify if it can be converted to an integer between the lower and upper bounds.
If possible, return an integer (instead of a text).
If it cannot, an error message is displayed and the integebox is redisplayed.
If the user cancels the operation, None is returned.
import easygui
result = easygui.integerbox('请输入一个整数:')
print(result)
Note: If the input integer exceeds the upper and lower limits or the input is not an integer, a msgbox will be returned:
button selection box 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)
Displays a message, title, image, and a set of buttons. Buttons are defined by members of the options parameter.
import easygui as eg
eg.buttonbox(msg='请选择:', title='自定义确认框', choices=('浏览...', '确定', '取消'), image=None, images=None, default_choice="确定", cancel_choice=None, callback=None, run=True)