Instead, EasyGui is basically a set of dialogs that can be opened on demand. This package would be handy for command line programs that. Tkinter is one of them, actually it is one of the oldest GUI toolkits. easygui is a Tkinter based module which has written to give access to the GUI. Thankfully, the EasyGui module allows you to add some GUI If you want to give EasyGui a try, make sure to peruse the EasyGui tutorial.

Author: Moogugal Goltisho
Country: Angola
Language: English (Spanish)
Genre: Science
Published (Last): 25 February 2007
Pages: 245
PDF File Size: 4.65 Mb
ePub File Size: 3.27 Mb
ISBN: 720-3-28984-139-3
Downloads: 54953
Price: Free* [*Free Regsitration Required]
Uploader: Arashisho

You may encounter problems using IDLE to run programs that use easygui. Try it and find out. IDLE is also a Tkinter application, with its own event loop. The two may conflict, with the unpredictable results.

If you find that you have problems, try running your program outside of IDLE. Here is a simple demo program using easygui. The screens that it produces are shown on the gallery page.

This will allow you to try out the tuutorial EasyGui functions, and will print the results of your choices to the console. One way to import EasyGui is to import everything. This makes it easy to invoke the EasyGui functions — you won’t have to put a prefix in front of the easygui function names. On the other hand, “import star” is a bad Python practice. We recommend importing easygui and giving it a short alias. This keeps the easygui namespace separate from your application’s namespace while requiring sasygui minimum amount of typing.

ICS3U Python easyGUI Primer – Mr. Liconti

For example, using EasyGui, the famous “Hello, world! To see examples of code that invokes the EasyGui functions, look at the demonstration code tutprial the end of tutoriaal. For all of the boxes, the first two arguments are for message and title, in that order. In some cases, this might not be the most user-friendly arrangment for example, the dialogs for getting directory and filenames ignore the message argumentbut I felt that keeping this consistent across all widgets was a consideration that is more important.

Most arguments to EasyGui functions have defaults.

Almost all of the boxes display a message and a title. The title defaults to the empty string, and the message usually has a simple default. This makes it is possible to specify as few arguments as you need in order to get the result that you want. For instance, the title argument to msgbox is optional, so you can call msgbox specifying only a message, this way:.

On the various types of buttonbox, the default message is “Shall I continue? It is possible to use keyword arguments when calling EasyGui functions. Prior to version 0. Suppose for instance that you wanted to use a buttonbox, but for whatever reason did not want to specify the title second positional argument. You could still specify the choices argument the third argument using a keyword, this way:.


You can send whatever message you want, along with whatever title you want. You can even over-ride the default text of “OK” on the button if you wish. Here is the signature of the msgbox function:. NOTE that this box returns integer values 1 and 0not true boolean values true and falsewhich became available in Python version 2. Returns the text of the button that the user selected. You have no choice about what buttons they display. It returns the index of the user’s choice.

For example, if you invoked index box with three choices A, B, Cindexbox would return 0 if the user picked A, 1 if he picked B, and 2 if he picked C. When you invoke the buttonbox function or other functions that display a button box, such as msgboxindexboxynboxetc. Buttonboxes are good for offering the user a small selection of short choices. But if there are many choices, or the text of the choices is long, then a better strategy is to present them as a list.

The choices are specified in a sequence a tuple or a list. The choices will be given a case-insensitive sort before they are presented. Pressing “g” on the keyboard, for example, will jump the selection to the first element beginning with “g”. Pressing “g” again, will jump the cursor to the next element beginning with “g”. At the end of the elements beginning with “g”, pressing “g” again will cause the selection to wrap around to the beginning of the list and jump to the first element beginning with “g”.

If there is no element beginning with “g”, then the last element that occurs before the position where “g” would occur is selected.

If there is no element before “g”, then the first element in the list is selected. The interface looks just like the choicebox, but the user may select zero, one, or multiple choices. 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. Here is some example code, that shows how values returned from multenterbox can be checked for validity before they are accepted.


Here is some example code, that shows how values returned from multpasswordbox can be checked for validity before they are accepted. A passwordbox box is like an enterbox, but used for entering passwords.

The text is masked as it is typed in.

Both of these boxes return their contents, so it is possible to use them as an alternative to enterbox for allowing the user to enter multiple lines of text. Note that you can pass these boxes either a string or a list of strings. A list of strings will be converted to text before being easyhui.

This means that you can use these boxes to display the contents of a file this way:. The textbox function displays text in a proportional font. The text will word-wrap.

Easygui: Make Graphical Programs With Python – Python Tutorials |

The codebox function displays text in a monospaced font and does not wrap. EasyGui provides some basic functions for navigating through the file system and choosing a directory or a file. These functions are wrappers around widgets and classes in lib-tk. Note that in the current version of EasyGui, the startpos argument is not supported. A common need is to ask the user for some setting, and then to “persist it”, or store it on disk, so that the next time the user uses your application, you can remember his previous setting.

In order to make the process of storing and restoring user settings, EasyGui provides a class called EgStore. In order to remember some settings, your application must define a class let’s call it Settingsalthough you can call it anything you want that inherits from EgStore.

Your application must also create an object of that class let’s call the object settings. Once you have done this, you can remember the settings simply by assigning values to instance variables in the settings object, and use the settings.

EasyGui Tutorial

Here is an example of code to create the settings object. Simply creating the settings object will restore its values from the settingsFile, if the settingsFile exists. Sometimes easyugi are raised Depending on how you run your application, the stack trace might be discarded or written to stdout while your application crashes.

EasyGui provides a better way of handling exceptions via exceptionbox. Exceptionbox displays the stack trace in a codebox and may allow you to continue processing.