msgbox(msg='(Your message goes here)’, title=’ ‘, ok_button=’OK’, image=None, root=None)
msgbox() Displays a message and provides a “OK” button. You can specify any message and title, and you can even rewrite the contents of the “OK” button. The following is the instance function of msgbox ():
#！/usr/bin/env python # -*- coding:utf-8 -*- # __Author__ = "Ma Qing" # __date__ = "2017/03/31" # __Desc__ = One of the simplest small windows similar to Java's MessageBox. import easygui as g #Most of the EasyGui functions have default parameters, and almost all components display a message and title. #The default is the empty string, which has a simple default value. #For example, the parameters of the header part of the msgbox () function are optional, so you can specify a message parameter when you call msgbox, for example: msg = g.msgbox("Hello Easy GUI") #Of course, you can also specify information parameters and header parameters. title = g.msgbox(msg="I must learn to program!",title="Title part",ok_button="Come on")
ccbox(msg=’Shall I continue?’, title=’ ‘, choices=(‘Continue’, ‘Cancel’), image=None)
ccbox() Provide a choice: Continue or Cancel, and return 1 (check Continue) or 0 (check Cancel) accordingly. Note that ccbox () returns 1 or 0 of the integer, not True of the boolean type.False. But you can still write this:
import sys import easygui as g if g.ccbox("Do you still play my dear?",choices=("And play!","Let's do it / O / ~ ~")): g.msgbox("Don't play, go to sleep.") else: sys.exit(0)
To be honest, this function is exactly the same as that of ccbox (). Let’s save a few crosses.
buttonbox(msg=”, title=’ ‘, choices=(‘Button1’, ‘Button2’, ‘Button3’), image=None, root=None)
You can use buttonbox () to define your own set of buttons. Buttonbox () displays a set of buttons that you define.
When the user clicks any button, buttonbox () returns the text content of the button. If the user cancels to cancel or close the window, the default option (the first option) will be returned. Look at the examples:
import easygui as g g.buttonbox(msg="What kind of fruit do you like?",title="",choices=("watermelon","Apple","Strawberry"))
indexbox(msg=’Shall I continue?’, title=’ ‘, choices=(‘Yes’, ‘No’), image=None)
Basically the same as above, the difference is that when the user selects the first button, he returns the serial number 0 and returns the serial number 1 when selecting the second button.
boolbox(msg=’Shall I continue?’, title=’ ‘, choices=(‘Yes’, ‘No’), image=None)
If the first button is selected, it returns 1, otherwise it returns 0.
7、Display pictures in buttonbox ()
When you call a buttonbox function, such as msgbox (), ynbox (), indexbox (), etc.,
You can also assign values for keyword parameter image, which is an image in a.Gif format (note only in GIF format).
import easygui as g g.buttonbox("Do you say the smell is lovely?",image="xiuxiu.gif",choices=("Lovely","Not lovely","Miser"))
choicebox(msg=’Pick something.’, title=’ ‘, choices=())
The button component provides a simple button option for the user, but if there are many options, or the options are particularly long, the better strategy is to provide them with an optional list.
choicebox() A selectable list is provided for the user, using the sequence (the ancestor or list) as an option that displays the preorder in the case of no case insensitive. It
In addition, you can use keyboard to choose one of them.
- For example, when you press the “g” button on the keyboard, the first option to start with “g” will be selected.
- Pressing the “g” button again will select the next option to start with “g”.
- When you select the last option that starts with “g”, press the “g” button again and return to the first option at the beginning of the list to start with “g”.
- If the option does not start with “g”, it will check the characters that are sorted before the character “g” (“F”).
- If there is no sort of character before “g” in the option, the first element in the list will be selected. It
To integrate the functions of documents we learned before, let’s take a popular example.
import easygui as g msg = "Choose an amateur life you like" title = "" choicess_list = ["Read a Book","Swimming","Ride on a bicycle","Play a game"] reply = g.choicebox(msg,choices=choicess_list)
multchoicebox(msg=’Pick as many items as you like.’, title=’ ‘, choices=(), **kwargs)
multchoicebox() The function also provides an optional list, unlike choicebox (), and multchoicebox () supports the user to select 0, 1, or multiple options. It
multchoicebox() Functions also use sequences (ancestor or list) as options, which indicate that they will be arranged in a case insensitive manner.
import easygui as g g.multchoicebox(msg="Which fruit would you like to choose?",title="",choices=("watermelon","Banana","Apple","Pear"))
enterbox(msg=’Enter something.’, title=’ ‘, default=”, strip=True, image=None, root=None)
enterbox() To provide users with a simplest input box, return the string entered by user.
The default value automatically removes the space from the beginning to the end. If you want to retain the first and last space, set the parameter strip=False.
import easygui as g g.enterbox(msg="Please say what you have in mind at this time",title="Whispering in the heart")
integerbox(msg=”, title=’ ‘, default=”, lowerbound=0, upperbound=99, image=None, root=None, **invalidKeywordArguments)
integerbox() To provide a simple input box for the user, the user can only enter the integer value of the range (the minimum value of the Lowerbound parameter set, the maximum value of the upperbound parameter), otherwise the user will be required to reenter it.
import easygui as g g.integerbox(msg="Please enter your score",title="Fractional statistics",lowerbound=0,upperbound=100)
multenterbox(msg=’Fill in values for the fields.’, title=’ ‘, fields=(), values=())
multenterbox() To provide users with multiple simple input boxes, we should pay attention to the following points:
- If the user enters a value less than the option, the value in the return list fills the user’s input with empty string.
- If the user enters more values than options, the value in the returned list will be truncated as the number of options.
- If the user cancels the operation, the value of the list or None value in the field is returned.
import easygui as g msg = "Please fill in the information (the item with the * number is required)." title = "Account Center" fieldNames = ["*User name","*Real name","Fixed telephone","*Phone number","QQ","*Email"] fieldValues =  fieldValues = g.multenterbox(msg,title,fieldNames) #print(fieldValues) while True: if fieldValues == None : break errmsg = "" for i in range(len(fieldNames)): option = fieldNames[i].strip() if fieldValues[i].strip() == "" and option == "*": errmsg += ("【%s】For a required item" %fieldNames[i]) if errmsg == "": break fieldValues = g.multenterbox(errmsg,title,fieldNames,fieldValues) print("The information you have filled out is as follows:%s" %str(fieldValues))
passwordbox(msg=’Enter your password.’, title=’ ‘, default=”, image=None, root=None)
passwordbox() Like enterbox () style, the difference is that the user input is displayed with “*” and returns the string entered by the user:
import easygui as g g.passwordbox(msg="Please enter your password")
import easygui as g msg = "Please enter your password" user_password = g.passwordbox(msg) print(str(user_password))
multpasswordbox(msg=’Fill in values for the fields.’, title=’ ‘, fields=(), values=())
multpasswordbox() The same interface is used with multenterbox (), but when it displays, the last input box appears as the form of the password (“*”):
import easygui as g msg = "Please enter the username and password" title = "User login interface" user_info =  user_info = g.multpasswordbox(msg,title,("User name","Password")) print(user_info)
textbox(msg=”, title=’ ‘, text=”, codebox=0)
textbox() The function default will display the content of the text in a proportional font (the parameter codebox=1 is set to an equal width font), which is suitable for displaying the general written text. It
Note: the text parameter (third parameters) can be string type, list type, or type of ancestor.