Python Module Easygui Detailed Introduction

Source: Internet
Author: User
Tags save file
Python Module Easygui Detailed Introduction

Objective:

When Windows wanted to develop some simple interfaces with Python, it found a Easygui library that was easy to get started with. Let's share the simple use below.

Next, I'll show you how to use this module from simple to complex a little bit. I hope I can give you a little help in your new contact with Easygui:-)

Msgbox,ccbox,ynbox

# coding:utf-8#  __author__ = ' Mark Sinoberg ' #  __date__ = ' 2016/5/25 ' #  __desc__ = A small window of the simplest Java-like messagebox import Easyguititle = Easygui.msgbox (msg= ' hint info ', title= ' title section ', ok_button= "OOK") msg = Easygui.msgbox (' Hello easy GUI ') print ' return value: ' + Msgccbox = Easygui.ccbox ("Here is Continue | Cancel box! ") print ' return value: ' + str (ccbox) Ynbox = Easygui.ynbox ("Yes Or No button box!") print ' return value: ' + str (ynbox)

Bottonbox

# coding:utf-8#  __author__ = ' Mark Sinoberg ' #  __date__ = ' 2016/5/25 ' #  __desc__ = A simple interface that allows you to initially choose, The second parameter is a list of import easygui# choice = Easygui.buttonbox ("Here is the statement information for the prompt: \ n", title= ' three-choice one ', choices=[' a ' \#   , ' two ', ' Three '] # Easygui.msgbox (' You have selected: ' + str (choice)) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Two, select which one will return 1 or 0#  Title= ' title section ', choices=[' A ', ' B ']) # Easygui.msgbox (bool) image = ' me.jpg ' msg = ' Here is my photo,a Python fan also ' choices = [' Yes ', ' No ', ' not sure ']title = ' Am I handsome? ' Easygui.buttonbox (msg,title,image=image,choices=choices)

Choicebox

# coding:utf-8#  __author__ = ' Mark Sinoberg ' #  __date__ = ' 2016/5/25 ' #  __desc__ = Select one of them from a list, There will be a return value of import easyguimsg = ' Select the one you like in this list item ' title = ' must choose a oh ' choices = [' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ']answer = Easygui.choicebox (msg,title,choices) print ' You have selected: ' + str (answer)

Enterbox

# coding:utf-8#  __author__ = ' Mark Sinoberg ' #  __date__ = ' 2016/5/25 ' #  __desc__ = controls that can satisfy user input import Easyguist = Easygui.enterbox ("Please enter a text: \ n") print "you entered:" + str (ST)

Mutilchoicebox

# coding:utf-8#  __author__ = ' Mark Sinoberg ' #  __date__ = ' 2016/5/25 ' #  __desc__ = A multi-select list item. hehe, this version seems to have a problem. My multi-choice does not really implement import easyguimsg = ' Select one of the items you like in this list ' title = ' must choose a oh ' choices = (1,2,3,4,5,6,7,8,9) Answer1 = Easygui.multchoicebox (msg,title,choices) for item in Answer1:  print Item

Intenterbox,passenterbox

# coding:utf-8#  __author__ = ' Mark Sinoberg ' #  __date__ = ' 2016/5/25 ' #  __desc__ = provides the user with a simple input box, Can only be the range of the given number import easyguimsg = ' Please enter a number, range in 0-100 ' title = ' limit to number type ' lowerbound = 0upperbound = 100default = ' image = ' me.jp G ' result = Easygui.integerbox (msg,title,default,lowerbound,upperbound,image) Print result

Textbox,codebox

# coding:utf-8#  __author__ = ' Mark Sinoberg ' #  __date__ = ' 2016/5/25 ' #  __desc__ = Easygui also provides support for large amounts of text, and support for code text Import easyguimsg = ' Large text support ' title = ' Text Code ' text = ' abcdefghijklmnopqrstuvwxyzabcdefghjiklmnopqrstuvwxyz0123456789-/' textcontent = Easygui.textbox (Msg,title,text) Codecontent = Easygui.codebox (Msg,title,) print Textcontentprint codecontent# D:\Software\Python2\python.exe e:/code/ python/mytestset/easygui_/text_codebox.py# abcdefghijklmnopqrstuvwxyzabcdefghjiklmnopqrstuvwxyz0123456789-/# public class helloworld{# public  static void main (String []args) {#    System.out.println ("Hello world!"); #  }#}## Process finished with exit code 0

Diropenbox

# coding:utf-8#  __author__ = ' Mark Sinoberg ' #  __date__ = ' 2016/5/25 ' #  __desc__ = This function is used to provide a dialog box that returns the directory name selected by the user, The directory name is the complete directory with the full path of the # selection cancel if the return value defaults to noneimport easyguimsg = ' Select a file and will return the full catalog of the file Oh ' title = ' File selection Dialog ' default = R ' F:\ Flappy-bird ' Full_file_path = Easygui.diropenbox (msg, title, default) print ' The full path of the selected file is: ' + str (full_file_path) # D:\ Software\python2\python.exe e:/code/python/mytestset/easygui_/diropenbox.py# The full path of the selected file is: F:\flappy-bird## Process finished with exit code 0

Fileopenbox

# coding:utf-8# __author__ = ' Mark Sinoberg ' # __date__ = ' 2016/5/25 ' # __desc__ = This method is used to provide a dialog box that returns the file name selected by the user, with the full path, select Canc El returns none# default= "c:/fishc/*.py" to display all Python files under the C:\FISHC folder. # default= "c:/fishc/test*.py" displays all Python files under the C:\FISHC folder whose names begin with Test. The # filetypes parameter is a list of strings that contain a file mask, which is remembered as a list. such as: FileTypes = ["*.css", ["*.htm", "*.html", "HTML files"]]import easyguimsg = ' Return the full path of the selected file, select Cancel to return none ' title = ' File selection Selector ' default = ' e:/code/python/mytestset/easygui/*.py ' opened_files = Easygui.fileopenbox (msg,title,default,multiple= True) for item in Opened_files:print item# D:\Software\Python2\python.exe e:/code/python/mytestset/easygui_/ fileopenbox.py# e:\code\python\mytestset\easygui_\me.jpg# e:\code\python\mytestset\easygui_\buttonbox.py# E:\Code \python\mytestset\easygui_\choicesbox.py# e:\code\python\mytestset\easygui_\diropenbox.py# E:\Code\Python\ mytestset\easygui_\enterbox.py# e:\code\python\mytestset\easygui_\fileopenbox.py# E:\Code\Python\MyTestSet\ Easygui_\integerbox.py## Process finished with exit code 0 

Filesavebox

# coding:utf-8#  __author__ = ' Mark Sinoberg ' #  __date__ = ' 2016/5/25 ' #  __desc__ = The function provides a dialog box, Let the user select the path to save the file (with the full path) Select Cancel to return the none# the        default parameter should contain a file name (for example, a filename that you currently need to save), but you can also set it to empty, or a wildcard character that contains a file format mask. #        FileTypes Reference as above fileopenboximport easyguimsg = ' Save your file ' title = "to Save file" default = ' E:/code/python/mytes tset/easygui/newfile.* ' savedfile = Easygui.filesavebox (msg,title,default) Print Savedfileprint ' Of course, Here is just a complete path plus file name, and will not really save to a file, save the file need to use the other library ' # D:\Software\Python2\python.exe E:/code/python/mytestset/easygui_ /filesavebox.py# e:\code\python\mytestset\easygui_\newfile.doc# Of course, here is just a complete path plus the file name, and will not really save as a file, Save file need to use other library # # Process finished with exit code 0

Exceptionbox

# coding:utf-8#  __author__ = ' Mark Sinoberg ' #  __date__ = ' 2016/5/25 ' #  __desc__ = This is a very useful dialog box, and when the application has an exception, You can use this to give the user-friendly interface prompt import Easyguitry:  int (' Exception ') except:  easygui.exceptionbox (' int type data conversion Error! Please check your data type! ') # will pop up an interface where content information can be defined by itself, as above. The following is a trace of the error message # Traceback (most recent called last): #  File "e:/code/python/mytestset/easygui_/exceptionbox.py", Line ten, in <module>#   int (' Exception ') # valueerror:invalid literal for int () with base: ' Exception '

Summarize

After reading these examples, you must have confidence in Easygui developing a simple desktop applet. (^__^) hehe ...

However, for more complex tasks, it is not enough to grasp these foundations. So we also need to dig up other Python-related modules. In the actual development, we can choose the most suitable module according to the difficulty of the task to develop.

Thank you for reading, hope to help everyone, thank you for the support of this site!

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.