Display a msgbox with choices of Yes and No.
The returned value is calculated this way:
if the first choice ("Yes") is chosen, or if the dialog is cancelled:
return True
else:
return False
If invoked without a msg argument, displays a generic request for a confirmation that the user wishes to continue. So it can be used this way:
if ynbox():
pass # continue
else:
sys.exit(0) # exit the program
Parameters: |
|
---|---|
Returns: | True if ‘Yes’ or dialog is cancelled, False if ‘No’ |
Display a msgbox with choices of Continue and Cancel.
The returned value is calculated this way:
if the first choice ("Continue") is chosen, or if the dialog is cancelled:
return True
else:
return False
If invoked without a msg argument, displays a generic request for a confirmation that the user wishes to continue. So it can be used this way:
if ccbox():
pass # continue
else:
sys.exit(0) # exit the program
Parameters: |
|
---|---|
Returns: | True if ‘Continue’ or dialog is cancelled, False if ‘Cancel’ |
Display a boolean msgbox.
The returned value is calculated this way:
if the first choice is chosen, or if the dialog is cancelled:
returns True
else:
returns False
Parameters: |
|
---|---|
Returns: | True if first button pressed or dialog is cancelled, False if second button is pressed |
Display a buttonbox with the specified choices.
Parameters: |
|
---|---|
Returns: | the index of the choice selected, starting from 0 |
Display a message box
Parameters: |
|
---|---|
Returns: | the text of the ok_button |
Display a msg, a title, an image, and a set of buttons. The buttons are defined by the members of the choices list.
Parameters: |
|
---|---|
Returns: | the text of the button that the user selected |
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 argument 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.
Parameters: |
|
---|---|
Returns: | the integer value entered by the user |
Show screen with multiple data entry fields.
If there are fewer values than names, the list of values is padded with empty strings until the number of values is the same as the number of names.
If there are more values than names, the list of values is truncated so that there are as many values as names.
Returns a list of the values of the fields, or None if the user cancels the operation.
Here is some example code, that shows how values returned from multenterbox can be checked for validity before they are accepted:
msg = "Enter your personal information"
title = "Credit Card Application"
fieldNames = ["Name","Street Address","City","State","ZipCode"]
fieldValues = [] # we start with blanks for the values
fieldValues = multenterbox(msg,title, fieldNames)
# make sure that none of the fields was left blank
while 1:
if fieldValues is None: break
errmsg = ""
for i in range(len(fieldNames)):
if fieldValues[i].strip() == "":
errmsg += ('"%s" is a required field.\n\n' % fieldNames[i])
if errmsg == "":
break # no problems found
fieldValues = multenterbox(errmsg, title, fieldNames, fieldValues)
writeln("Reply was: %s" % str(fieldValues))
Parameters: |
|
---|---|
Returns: | String |
Show a box in which a user can enter some text.
You may optionally specify some default text, which will appear in the enterbox when it is displayed.
Example:
reply = enterbox(....)
if reply:
...
else:
...
Parameters: |
|
---|---|
Returns: | the text that the user entered, or None if he cancels the operation. |
Display a box that gives information about an exception that has just been raised.
The caller may optionally pass in a title for the window, or a msg to accompany the error information.
Note that you do not need to (and cannot) pass an exception object as an argument. The latest exception will automatically be used.
Parameters: |
|
---|---|
Returns: | None |
Present the user with a list of choices. return the choice that he selects.
Parameters: |
|
---|---|
Returns: | List containing choice selected or None if cancelled |
Display some text in a monospaced font, with no line wrapping. This function is suitable for displaying code and text that is formatted using spaces.
The text parameter should be a string, or a list or tuple of lines to be displayed in the textbox.
Parameters: |
|
---|
Display some text in a proportional font with line wrapping at word breaks. This function is suitable for displaying general written text.
The text parameter should be a string, or a list or tuple of lines to be displayed in the textbox.
Parameters: |
|
---|
A dialog to get a directory name. Note that the msg argument, if specified, is ignored.
Returns the name of a directory, or None if user chose to cancel.
If the “default” argument specifies a directory name, and that directory exists, then the dialog box will start with that directory.
Parameters: |
|
---|---|
Returns: | Normalized path selected by user |
A dialog to get a file name.
About the “default” argument
The “default” argument specifies a filepath that (normally) contains one or more wildcards. fileopenbox will display only files that match the default filepath. If omitted, defaults to “*” (all files in the current directory).
WINDOWS EXAMPLE:
...default="c:/myjunk/*.py"
will open in directory c:myjunkand show all Python files.
WINDOWS EXAMPLE:
...default="c:/myjunk/test*.py"
will open in directory c:myjunkand show all Python files whose names begin with “test”.
Note that on Windows, fileopenbox automatically changes the path separator to the Windows path separator (backslash).
About the “filetypes” argument
If specified, it should contain a list of items, where each item is either:
EXAMPLE:
filetypes = ["*.css", ["*.htm", "*.html", "HTML files"] ]
Note
If the filetypes list does not contain (“All files”,”*”), it will be added.
If the filetypes list does not contain a filemask that includes the extension of the “default” argument, it will be added. For example, if default=”*abc.py” and no filetypes argument was specified, then “*.py” will automatically be added to the filetypes argument.
Parameters: |
|
---|---|
Returns: | the name of a file, or None if user chose to cancel |
A file to get the name of a file to save. Returns the name of a file, or None if user chose to cancel.
The “default” argument should contain a filename (i.e. the current name of the file to be saved). It may also be empty, or contain a filemask that includes wildcards.
The “filetypes” argument works like the “filetypes” argument to fileopenbox.
Parameters: |
|
---|---|
Returns: | the name of a file, or None if user chose to cancel |
Show a box in which a user can enter a password. The text is masked with asterisks, so the password is not displayed.
Parameters: |
|
---|---|
Returns: | the text that the user entered, or None if he cancels the operation. |
Same interface as multenterbox. But in multpassword box, the last of the fields is assumed to be a password, and is masked with asterisks.
Parameters: |
|
---|---|
Returns: | String |
Example
Here is some example code, that shows how values returned from multpasswordbox can be checked for validity before they are accepted:
msg = "Enter logon information"
title = "Demo of multpasswordbox"
fieldNames = ["Server ID", "User ID", "Password"]
fieldValues = [] # we start with blanks for the values
fieldValues = multpasswordbox(msg,title, fieldNames)
# make sure that none of the fields was left blank
while 1:
if fieldValues is None: break
errmsg = ""
for i in range(len(fieldNames)):
if fieldValues[i].strip() == "":
errmsg = errmsg + ('"%s" is a required field.\n\n' % fieldNames[i])
if errmsg == "": break # no problems found
fieldValues = multpasswordbox(errmsg, title, fieldNames, fieldValues)
writeln("Reply was: %s" % str(fieldValues))
Present the user with a list of choices. allow him to select multiple items and return them in a list. if the user doesn’t choose anything from the list, return the empty list. return None if he cancelled selection.
Parameters: |
|
---|---|
Returns: | List containing choice selected or None if cancelled |
shows the easygui revision history
Run the EasyGui demo.
A class to support persistent storage.
You can use EgStore to support the storage and retrieval of user settings for an EasyGui application.
Example A: define a class named Settings as a subclass of EgStore
class Settings(EgStore):
def __init__(self, filename): # filename is required
#-------------------------------------------------
# Specify default/initial values for variables that
# this particular application wants to remember.
#-------------------------------------------------
self.userId = ""
self.targetServer = ""
#-------------------------------------------------
# For subclasses of EgStore, these must be
# the last two statements in __init__
#-------------------------------------------------
self.filename = filename # this is required
self.restore() # restore values from the storage file if possible
Example B: create settings, a persistent Settings object
settingsFile = "myApp_settings.txt"
settings = Settings(settingsFile)
user = "obama_barak"
server = "whitehouse1"
settings.userId = user
settings.targetServer = server
settings.store() # persist the settings
# run code that gets a new value for userId, and persist the settings
user = "biden_joe"
settings.userId = user
settings.store()
Example C: recover the Settings instance, change an attribute, and store it again.
settings = Settings(settingsFile)
settings.userId = "vanrossum_g"
settings.store()
Delete my persistent file (i.e. pickle file), if it exists.
Set the values of whatever attributes are recoverable from the pickle file.
Populate the attributes (the __dict__) of the EgStore object from the attributes (the __dict__) of the pickled object.
If the pickled object has attributes that have been initialized in the EgStore object, then those attributes of the EgStore object will be replaced by the values of the corresponding attributes in the pickled object.
If the pickled object is missing some attributes that have been initialized in the EgStore object, then those attributes of the EgStore object will retain the values that they were initialized with.
If the pickled object has some attributes that were not initialized in the EgStore object, then those attributes will be ignored.
IN SUMMARY:
After the recover() operation, the EgStore object will have all, and only, the attributes that it had when it was initialized.
Where possible, those attributes will have values recovered from the pickled object.
Save the attributes of the EgStore object to a pickle file. Note that if the directory for the pickle file does not already exist, the store operation will fail.