Point of Knowledge: Easygui python visual programming

Source: Internet
Author: User

Original site: http://bbs.fishc.com/forum.php?mod=viewthread&tid=46069&extra=page%3D1%26filter%3Dtypeid%26typeid% 3d403

Various functions of 1:easygui demo

To run the Easygui demo program,

Method 1: Call Easygui at command-line cmd

C:\Python33\python.exe easygui.py

Method 2: Run on idle

 as Gg.egdemo ()

After a successful call you will be able to try the various features that Easygui has and print the results of your choice to the console.

2: Import Easygui

Method 1: The simplest import method, when using Easygui functions, must precede the function with a prefix Easygui

Import Easyguieasygui.msgbox ("hello")

Method 2: Choose to import the entire Easygui package, which makes it easier for us to call Easygui's function, you can write the code directly

 from Import *MsgBox ("hello")

Method 3: the recommended method. This allows you to maintain a Easygui namespace while reducing your typing volume. After the import, you can call Easygui's function like this.

Import Easygui as Gg.msgbox ("hello")

Default parameters for the 3:easygui function

For all functions, the first two arguments are messages and headers. Most of the Easygui functions have default parameters, and almost all components display a message and a caption. The title defaults to an empty string, and the information usually has a simple default value.

In the various button components, the default message is "Shall I continue?", so you can call them without any parameters. Here we demonstrate to call Ccbox () without any parameters, and return a Boolean value when you select "Cancel" or close the window:

Import Easygui as Gg.ccbox ()

"Continue"---> Return 1

"Cancel"---> Return 0

4: Call the Easygui function with the keyword argument

Suppose you need to use a button component, but you do not want to specify a caption parameter (the second parameter), you can still specify the choices parameter (the third parameter) by using the method of the keyword argument

Import Easygui as gchoices=[" willing ","  unwilling ","  When you're rich, you're willing to "]reply=g.choicebox (" will you marry me?  ", Choices=choices)

5: Button assembly

5.1:msgbox ()

MsgBox (msg='(Your message goes here)', title=', ok_button=' OK ', Image=none, Root=none)  #返回值: "OK"

MsgBox () displays a message and provides an "OK" button, you can specify any message and caption, you can even rewrite the contents of the "OK" button

The simplest way to modify the contents of a button is to use the keyword parameter

Import Easygui as Gg.msgbox (" I want to be first!  ", ok_button=' refueling ',")

5.2:ccbox ()

Ccbox (msg='shall I continue? ', title=', choices= ('Continue'Cancel '), Image=none)  #返回值 continue:1  cancel:0  choices can have more than two buttons, but only the first button returns 1, the others return 0 

Ccbox () provides a choice: Continue or Cancel, and returns 1 (checked Continue) or 0 (check cancel)

Note that Ccbox () is the return integer of 1 or 0, which is not a Boolean type of True or False. But you can still write this:

Import Easygui as G Import SYS if g.ccbox (" do you want to do it again?")  "choices= (" ^_^"," Forget it t_t"  ):    g.msgbox (" do not play, then play Bad ")else:    Sys.exit (0)

5.3ynbox () #和CCbox类似

Ynbox (msg='shall I continue? ', title=', choices= ('Yes''No' ), Image=none)   #返回值 yes:1  no:0  choices can have more than two buttons, but only the first button returns 1, the others return 0

5.4 Buttonbox ()

Buttonbox (msg=", title=", choices= ('Button1' ) Button2 ' ' Button3 ' #返回值 Returns the text content of the button

You can use Buttonbox () to define your own set of buttons, and Buttonbox () displays a set of buttons that you define

When the user clicks on any of the buttons, Buttonbox () returns the text content of the button. If the user cancels or closes the window, the default option (the first option) is returned.

Import Easygui as G G.buttonbox (" what kind of fruit do you like?")  ", choices= (" Apple "," banana ","  Orange "," watermelon "))

5.5 Indexbox ()

Indexbox (msg='shall I continue? ', title=', choices= ('Yes''No'  #返回值 Returns the ordinal of each button, starting with 0 yes:0,no:1 ....

Basically the same as Buttonbox, the difference is when the user selects the first button to return the ordinal 0, select the second button when the return sequence number 1

5.6 Boolbox ()

Boolbox (msg='shall I continue? ', title=', choices= ('Yes''No' ), Image=none) #返回值 The first button is selected to return 1, the second button is selected to return 0

6: How to display the picture inside the Buttonbox

When you call a Buttonbox function (such as MsgBox (), Ynbox (), Indexbox (), and so on), you can also assign a value to the keyword parameter image, which is an image in a. gif format (note that only GIF format is supported)

G.buttonbox (' Everybody say I'm handsome?  ', image='wugui.gif', choices= (' handsome  ') not handsome . ' ' [Email protected]#$% '))

7: Option Component

7.1 choicebox ()

Choicebox (msg='Pick something. ', title=', choices= ()) # Double-click an option in the list or select the contents of the return option with the OK button  to  return only one

button components provide users with a simple button option, but a better strategy is to provide them with an optional list if there are many options, or if the content of the option is particularly long.

Choicebox () provides the user with an optional list that uses a sequence (a tuple or list) as an option, which is ordered in a case-insensitive manner before being displayed.

In addition to using the mouse to select options in the list, you can also select by keyboard, depending on the character of the keyboard.

Import Easygui as gchoices=[" willing ","  unwilling ","  When you're rich, you're willing to "]reply=g.choicebox (" will you marry me?  ", Choices=choices)

7.2 Multchoicebox ()

Multchoicebox (msg='Pick as many items as you. ', title='# Returns a list of values. Double-clicking an option in the list returns an empty list, which must be selected with the OK button

The Multchoicebox () function also provides an optional list, unlike Choicebox (), Multchoicebox () allows the user to select 0, 1, or multiple options simultaneously

The Multchoicebox () function is also used as an option for sequences (tuples or lists), which appear to be ordered in a case-insensitive manner before they are displayed.

>>> choices=[" Beijing "," Tianjin "," Shanghai  "]>>> g.multchoicebox (" which city do you like? ")  ", Choices=choices)

8: User input component

8.1 Enterbox ()

Enterbox (msg='Enter something. ', title=', default='#返回值为用户输入的字符串

Enterbox () provides the user with one of the simplest input boxes, with the return value as a string entered by the user. The value returned by default automatically removes the leading and trailing spaces, set the parameter if you need to keep the Strip=false

8.2 Integerbox ()

Integerbox (msg=", title=", default="#返回值为用户输入的数字

Integerbox () provides the user with a simple input box, the user can only enter the range (lowerbound: Minimum, upperbound: maximum) of the integer value, or will require the user to re-enter

8.3 Multenterbox ()

Multenterbox (msg='Fill in Values for the fields. ', title=', fields= (), values= ()) #返回一个列表, list content is what is entered in each input field
G.multenterbox (" Please enter the following personal information "," personal information ", [" name "," gender "," age "])

Multenterbox () to provide users with a number of simple input boxes, pay attention to the following points:

If the user enters a value that is less than the option, the value in the returned list fills the user with an empty string for the input option.

If the user enters more than one option, the value in the returned list is truncated to the number of options.

If the user cancels the operation, the value of the list in the domain or the None value is returned.

Point of Knowledge: Easygui python visual programming

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.