Module easygui |
[hide private]
[frames] | no frames]

# Module easygui

source code

Version: 0.96(2010-08-29)

Notes:

- ABOUT EASYGUI

  EasyGui provides an easy-to-use interface for simple GUI interaction with a user. It does not require the programmer to know anything about tkinter, frames, widgets, callbacks or lambda. All GUI interactions are invoked by simple function calls that return results.

- WARNING about using EasyGui with IDLE

  You may encounter problems using IDLE to run programs that use EasyGui. Try it and find out. EasyGui is a collection of Tkinter routines that run their own event loops. IDLE is also a Tkinter application, with its own event loop. The two may conflict, with unpredictable results. If you find that you have problems, try running your EasyGui program outside of IDLE.

  Note that EasyGui requires Tk release 8.0 or greater.

- LICENSE INFORMATION

  EasyGui version 0.96

  Copyright (c) 2010, Stephen Raymond Ferg

  All rights reserved.

  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

- ABOUT THE EASYGUI LICENSE

  This license is what is generally known as the "modified BSD license", aka "revised BSD", "new BSD", "3-clause BSD". See http://www.opensource.org/licenses/bsd-license.php

  This license is GPL-compatible. See http://en.wikipedia.org/wiki/License_compatibility See http://www.gnu.org/licenses/license-list.html#GPLCompatibleLicenses

  The BSD License is less restrictive than GPL. It allows software released under the license to be incorporated into proprietary products. Works based on the software may be released under a proprietary license or as closed source software. http://en.wikipedia.org/wiki/BSD_licenses#3-clause_license_.28.22New_BSD_License.22.29

Classes | [hide private]
| FileTypeObject
| EgStore A class to support persistent storage.

Functions | [hide private]
write(*args) | source code
writeln(*args) | source code
say(*args) | source code
dq(s) | source code
ynbox(msg=`'``Shall I continue?``'`, title=`'``` `'`, choices=`(``'``Yes``'``,` `'``No``'``)`, image=None) Display a msgbox with choices of Yes and No. | source code
ccbox(msg=`'``Shall I continue?``'`, title=`'``` `'`, choices=`(``'``Continue``'``,` `'``Cancel``'``)`, image=None) Display a msgbox with choices of Continue and Cancel. | source code
boolbox(msg=`'``Shall I continue?``'`, title=`'``` `'`, choices=`(``'``Yes``'``,` `'``No``'``)`, image=None) Display a boolean msgbox. | source code
indexbox(msg=`'``Shall I continue?``'`, title=`'``` `'`, choices=`(``'``Yes``'``,` `'``No``'``)`, image=None) Display a buttonbox with the specified choices. | source code
msgbox(msg=`'``(Your message goes here)``'`, title=`'``` `'`, ok_button=`'``OK``'`, image=None, root=None) Display a messagebox | source code
buttonbox(msg=`'````'`, title=`'``` `'`, choices=`(``'``Button1``'``,` `'``Button2``'``,` `'``Button3``'``)`, image=None, root=None) Display a msg, a title, and a set of buttons. | source code
integerbox(msg=`'````'`, title=`'``` `'`, default=`'````'`, lowerbound=0, upperbound=99, image=None, root=None, **invalidKeywordArguments) Show a box in which a user can enter an integer. | source code
multenterbox(msg=`'``Fill in values for the fields.``'`, title=`'``` `'`, fields=`(``)`, values=`(``)`) Show screen with multiple data entry fields. | source code
multpasswordbox(msg=`'``Fill in values for the fields.``'`, title=`'``` `'`, fields=`(``)`, values=`(``)`) Same interface as multenterbox. | source code
bindArrows(widget) | source code
tabRight(event) | source code
tabLeft(event) | source code
__multfillablebox(msg=`'``Fill in values for the fields.``'`, title=`'``` `'`, fields=`(``)`, values=`(``)`, mask=None) | source code
__multenterboxGetText(event) | source code
__multenterboxCancel(event) | source code
enterbox(msg=`'``Enter something.``'`, title=`'``` `'`, default=`'````'`, strip=True, image=None, root=None) Show a box in which a user can enter some text. | source code
passwordbox(msg=`'``Enter your password.``'`, title=`'``` `'`, default=`'````'`, image=None, root=None) Show a box in which a user can enter a password. | source code
__fillablebox(msg, title=`'````'`, default=`'````'`, mask=None, image=None, root=None) Show a box in which a user can enter some text. | source code
__enterboxGetText(event) | source code
__enterboxRestore(event) | source code
__enterboxCancel(event) | source code
denyWindowManagerClose() don't allow WindowManager close | source code
multchoicebox(msg=`'``Pick as many items as you like.``'`, title=`'``` `'`, choices=`(``)`, **kwargs) Present the user with a list of choices. | source code
choicebox(msg=`'``Pick something.``'`, title=`'``` `'`, choices=`(``)`) Present the user with a list of choices. | source code
__choicebox(msg, title, choices) internal routine to support choicebox() and multchoicebox() | source code
__choiceboxGetChoice(event) | source code
__choiceboxSelectAll(event) | source code
__choiceboxClearAll(event) | source code
__choiceboxCancel(event) | source code
KeyboardListener(event) | source code
exception_format() Convert exception info into a string suitable for display. | source code
exceptionbox(msg=None, title=None) Display a box that gives information about an exception that has just been raised. | source code
codebox(msg=`'````'`, title=`'``` `'`, text=`'````'`) Display some text in a monospaced font, with no line wrapping. | source code
textbox(msg=`'````'`, title=`'``` `'`, text=`'````'`, codebox=0) Display some text in a proportional font with line wrapping at word breaks. | source code
__textboxOK(event) | source code
diropenbox(msg=None, title=None, default=None) A dialog to get a directory name. | source code
getFileDialogTitle(msg, title) | source code
string or None |
fileopenbox(msg=None, title=None, default=`'``*``'`, filetypes=None) A dialog to get a file name. | source code
filesavebox(msg=None, title=None, default=`'````'`, filetypes=None) A file to get the name of a file to save. | source code
fileboxSetup(default, filetypes) | source code
__buttonEvent(event) Handle an event that is generated by a person clicking a button. | source code
__put_buttons_in_buttonframe(choices) Put the buttons in the buttons frame | source code
egdemo() Run the EasyGui demo. | source code
_demo_textbox(reply) | source code
_demo_codebox(reply) | source code
_demo_buttonbox_with_image() | source code
_demo_help() | source code
_demo_filesavebox() | source code
_demo_diropenbox() | source code
_demo_fileopenbox() | source code
_dummy() | source code
abouteasygui() shows the easygui revision history | source code

Variables | [hide private]
| egversion = ``'``0.96(2010-08-29)``'``
| runningPython26 = `True`
| runningPython3 = `False`
| PILisLoaded = `True`
| stars = `"*"* 75`
| rootWindowPosition = ``'``+300+200``'``
| PROPORTIONAL_FONT_FAMILY = ``(``'``MS``'``,` `'``Sans``'``,` `'``Serif``'``)``
| MONOSPACE_FONT_FAMILY = ``'``Courier``'``
| PROPORTIONAL_FONT_SIZE = `10`
| MONOSPACE_FONT_SIZE = `9`
| TEXT_ENTRY_FONT_SIZE = `12`
| STANDARD_SELECTION_EVENTS = ``[``'``Return``'``,` `'``Button-1``'``,` `'``space``'``]``
| __choiceboxMultipleSelect = `None`
| __widgetTexts = `None`
| __replyButtonText = `None`
| __choiceboxResults = `None`
| __firstWidget = `None`
| __enterboxText = `None`
| __enterboxDefaultText = ``'````'``
| __multenterboxText = ``'````'``
| choiceboxChoices = `None`
| choiceboxWidget = `None`
| entryWidget = `None`
| boxRoot = `None`
| ImageErrorMsg = ``'``\n\n-----------------------------------------``...``
| EASYGUI_ABOUT_INFORMATION = ``'``\n===============================``...``
| __package__ = `None`

Function Details | [hide private]

### ynbox(msg=`'``Shall I continue?``'`, title=`'``` `'`, choices=`(``'``Yes``'``,` `'``No``'``)`, image=None) | source code
Display a msgbox with choices of Yes and No. The default is "Yes". The returned value is calculated this way:
           if the first choice ("Yes") is chosen, or if the dialog is cancelled:
                   return 1
           else:
                   return 0
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: `msg` - the msg to be displayed. `title` - the window title `choices` - a list or tuple of the choices to be displayed

### ccbox(msg=`'``Shall I continue?``'`, title=`'``` `'`, choices=`(``'``Continue``'``,` `'``Cancel``'``)`, image=None) | source code
Display a msgbox with choices of Continue and Cancel. The default is "Continue". The returned value is calculated this way:
           if the first choice ("Continue") is chosen, or if the dialog is cancelled:
                   return 1
           else:
                   return 0
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: `msg` - the msg to be displayed. `title` - the window title `choices` - a list or tuple of the choices to be displayed

### boolbox(msg=`'``Shall I continue?``'`, title=`'``` `'`, choices=`(``'``Yes``'``,` `'``No``'``)`, image=None) | source code
Display a boolean msgbox. The default is the first choice. The returned value is calculated this way:
           if the first choice is chosen, or if the dialog is cancelled:
                   returns 1
           else:
                   returns 0

### indexbox(msg=`'``Shall I continue?``'`, title=`'``` `'`, choices=`(``'``Yes``'``,` `'``No``'``)`, image=None) | source code
Display a buttonbox with the specified choices. Return the index of the choice selected.

### buttonbox(msg=`'````'`, title=`'``` `'`, choices=`(``'``Button1``'``,` `'``Button2``'``,` `'``Button3``'``)`, image=None, root=None) | source code
Display a msg, a title, and a set of buttons. The buttons are defined by the members of the choices list. Return the text of the button that the user selected. Parameters: `msg` - the msg to be displayed. `title` - the window title `choices` - a list or tuple of the choices to be displayed

### integerbox(msg=`'````'`, title=`'``` `'`, default=`'````'`, lowerbound=0, upperbound=99, image=None, root=None, **invalidKeywordArguments) | source code
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. NOTE that the "argLowerBound" and "argUpperBound" arguments are no longer supported. They have been replaced by "upperbound" and "lowerbound".

### multenterbox(msg=`'``Fill in values for the fields.``'`, title=`'``` `'`, fields=`(``)`, values=`(``)`) | source code
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 == 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: `msg` - the msg to be displayed. `title` - the window title `fields` - a list of fieldnames. `values` - a list of field values

### multpasswordbox(msg=`'``Fill in values for the fields.``'`, title=`'``` `'`, fields=`(``)`, values=`(``)`) | source code
Same interface as multenterbox. But in multpassword box, the last of the fields is assumed to be a password, and is masked with asterisks. # 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 == 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))

### enterbox(msg=`'``Enter something.``'`, title=`'``` `'`, default=`'````'`, strip=True, image=None, root=None) | source code
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. Returns the text that the user entered, or None if he cancels the operation. By default, enterbox strips its result (i.e. removes leading and trailing whitespace). (If you want it not to strip, use keyword argument: strip=False.) This makes it easier to test the results of the call:
           reply = enterbox(....)
           if reply:
                   ...
           else:
                   ...

### passwordbox(msg=`'``Enter your password.``'`, title=`'``` `'`, default=`'````'`, image=None, root=None) | source code
Show a box in which a user can enter a password. The text is masked with asterisks, so the password is not displayed. Returns the text that the user entered, or None if he cancels the operation.

### __fillablebox(msg, title=`'````'`, default=`'````'`, mask=None, image=None, root=None) | source code
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. Returns the text that the user entered, or None if he cancels the operation.

### multchoicebox(msg=`'``Pick as many items as you like.``'`, title=`'``` `'`, choices=`(``)`, **kwargs) | source code
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: `msg` - the msg to be displayed. `title` - the window title `choices` - a list or tuple of the choices to be displayed

### choicebox(msg=`'``Pick something.``'`, title=`'``` `'`, choices=`(``)`) | source code
Present the user with a list of choices. return the choice that he selects. return None if he cancels the selection selection. Parameters: `msg` - the msg to be displayed. `title` - the window title `choices` - a list or tuple of the choices to be displayed

### exceptionbox(msg=None, title=None) | source code
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.

### codebox(msg=`'````'`, title=`'``` `'`, text=`'````'`) | source code
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.

### textbox(msg=`'````'`, title=`'``` `'`, text=`'````'`, codebox=0) | source code
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.

### diropenbox(msg=None, title=None, default=None) | source code
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.

### fileopenbox(msg=None, title=None, default=`'``*``'`, filetypes=None) | source code
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:\myjunk\ and show all Python files. WINDOWS EXAMPLE:
           ...default="c:/myjunk/test*.py"
will open in directory c:\myjunk\ and 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:
           - a string containing a filemask          # e.g. "*.txt"
           - a list of strings, where all of the strings except the last one
                   are filemasks (each beginning with "*.",
                   such as "*.txt" for text files, "*.py" for Python files, etc.).
                   and the last string contains a filetype description
EXAMPLE:
           filetypes = ["*.css", ["*.htm", "*.html", "HTML files"]  ]
# NOTE THAT 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: `msg` - the msg to be displayed. `title` - the window title `default` - filepath with wildcards `filetypes` - filemasks that a user can choose, e.g. "*.txt" Returns: string or None the name of a file, or None if user chose to cancel

### filesavebox(msg=None, title=None, default=`'````'`, filetypes=None) | source code
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.

Variables Details | [hide private]

  ### ImageErrorMsg Value:
      '''

      ---------------------------------------------
      Error: %s
      %s'''

  ### EASYGUI_ABOUT_INFORMATION Value:
      '''
      ======================================================================
      ==
      0.96(2010-08-29)
      ======================================================================
      ==
      This version fixes some problems with version independence.

      ...