Home Backend Development Python Tutorial Detailed introduction to Python module EasyGui

Detailed introduction to Python module EasyGui

Feb 20, 2017 am 10:23 AM

Detailed introduction to Python module EasyGui

Foreword:

I want to use Python to develop some simple interfaces in Windows, so I found EasyGui library that is easy to use. Let me share the simple use below.

Next, I will demonstrate how to use this module from simple to more complex. I hope it can help you who are new to easygui:-)

msgBox,ccbox,ynbox

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

# coding:utf-8

 

#  __author__ = 'Mark sinoberg'

#  __date__ = '2016/5/25'

#  __Desc__ = 一个最简单的类似于Java的MessageBox的小窗口

 

import easygui

title = easygui.msgbox(msg='提示信息',title='标题部分',ok_button="OOK")

 

msg = easygui.msgbox('Hello Easy GUI')

print '返回值:' + msg

 

ccbox = easygui.ccbox("here is Continue | Cancel Box!")

print '返回值:' + str(ccbox)

 

ynbox = easygui.ynbox("Yes Or No Button Box!")

print '返回值: ' + str(ynbox)

Copy after login

bottonbox

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

# coding:utf-8

 

#  __author__ = 'Mark sinoberg'

#  __date__ = '2016/5/25'

#  __Desc__ = 能让你最初选择的简单的界面,第二个参数为一个列表

 

import easygui

 

# choice = easygui.buttonbox("这里是提示的语句信息:\n", title='三选一', choices=['one' \

#   , 'two', 'three'])

# easygui.msgbox('您选择了:' + str(choice))

#

# # choices 内只能有两个参数 ,选择哪一个将返回1,否则返回0

# bool = easygui.boolbox('msg提示信息', title='标题部分', 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)

Copy after login

choicebox

1

2

3

4

5

6

7

8

9

10

11

12

13

# coding:utf-8

 

#  __author__ = 'Mark sinoberg'

#  __date__ = '2016/5/25'

#  __Desc__ = 从一个列表中选择其中的一个,会有返回值的出现

 

import easygui

 

msg = '选择此列表项中你喜欢的一个吧'

title = '必须选择一个哦'

choices = ['1','2','3','4','5','6','7']

answer = easygui.choicebox(msg,title,choices)

print '你选择了 :' + str(answer)

Copy after login

enterbox

1

2

3

4

5

6

7

8

9

10

# coding:utf-8

 

#  __author__ = 'Mark sinoberg'

#  __date__ = '2016/5/25'

#  __Desc__ = 可以满足用户输入的控件

 

import easygui

 

st = easygui.enterbox("请输入一段文字:\n")

print "您输入了: " + str(st)

Copy after login

mutilchoicebox

1

2

3

4

5

6

7

8

9

10

11

12

13

14

# coding:utf-8

 

#  __author__ = 'Mark sinoberg'

#  __date__ = '2016/5/25'

#  __Desc__ = 一个多选的列表项.呵呵了,这个版本貌似有问题。我的多选并没有真正的实现

 

import easygui

 

msg = '选择此列表项中你喜欢的一个吧'

title = '必须选择一个哦'

choices = (1,2,3,4,5,6,7,8,9)

answer1 = easygui.multchoicebox(msg,title,choices)

for item in answer1:

  print item

Copy after login

intenterbox,passenterbox

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

# coding:utf-8

 

#  __author__ = 'Mark sinoberg'

#  __date__ = '2016/5/25'

#  __Desc__ = 提供给用户简单的输入框,只能是给定的数字的范围

 

import easygui

 

msg = '请输入一个数字,范围在0-100'

title = '限制为数字类型'

lowerbound = 0

upperbound = 100

default = ''

image = 'me.jpg'

result = easygui.integerbox(msg,title,default,lowerbound,upperbound,image)

print result

Copy after login

textbox,codebox

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

# coding:utf-8

 

#  __author__ = 'Mark sinoberg'

#  __date__ = '2016/5/25'

#  __Desc__ = easygui 还提供了对大量文本的支持,以及对代码文本的支持

 

import easygui

 

msg = '大文本的支持'

title = 'Text Code'

text = 'abcdefghijklmnopqrstuvwxyzABCDEFGHJIKLMNOPQRSTUVWXYZ0123456789-/'

textContent = easygui.textbox(msg,title,text)

codeContent = easygui.codebox(msg,title,)

print textContent

print 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

Copy after login

diropenbox

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

# coding:utf-8

 

#  __author__ = 'Mark sinoberg'

#  __date__ = '2016/5/25'

#  __Desc__ = 该函数用于提供一个对话框,返回用户选择的目录名,该目录名是带有完整的路径的

# 选择Cancel的话返回值默认为None

 

import easygui

 

msg = '选择一个文件,将会返回该文件的完整的目录哦'

title = ' 文件选择对话框'

default = r'F:\flappy-bird'

full_file_path = easygui.diropenbox(msg, title, default)

print '选择的文件的完整的路径为:' + str(full_file_path)

 

 

# D:\Software\Python2\python.exe E:/Code/Python/MyTestSet/easygui_/diropenbox.py

# 选择的文件的完整的路径为:F:\flappy-bird

#

# Process finished with exit code 0

Copy after login

fileopenbox

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

# coding:utf-8

 

#  __author__ = 'Mark sinoberg'

#  __date__ = '2016/5/25'

#  __Desc__ = 此方法用于提供一个对话框,返回用户选择的文件名,带有完整的路径,选择Cancel返回None

#       default="c:/fishc/*.py" 即显示 C:\fishc 文件夹下所有的 Python 文件。

#       default="c:/fishc/test*.py" 即显示 C:\fishc 文件夹下所有的名字以 test 开头的 Python 文件。

#       filetypes参数是包含文件掩码的字符串的列表,记住是个列表。如:filetypes = ["*.css", ["*.htm", "*.html", "HTML files"]]

 

import easygui

 

msg = '返回选择的文件的完整的路径,选择Cancel则返回None'

title = '文件选择器'

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

Copy after login

filesavebox

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

# coding:utf-8

 

#  __author__ = 'Mark sinoberg'

#  __date__ = '2016/5/25'

#  __Desc__ = 该函数提供了一个对话框,让用户选择文件需要保存的路径(带完整的路径)选择Cancel返回None

#        default 参数应该包含一个文件名(例如当前需要保存的文件名),当然你也可以设置为空的,或者包含一个文件格式掩码的通配符。

#        filetypes参考如上面的fileopenbox

 

import easygui

 

msg = 'Save your file'

title = "to Save File"

default = 'E:/Code/Python/MyTestSet/easygui/newFile.*'

savedfile = easygui.filesavebox(msg,title,default)

print savedfile

print '当然了,这里仅仅是一个完整的路径加上文件名而已,并不会真的保存成一个文件,保存文件需要用到其他的库'

 

 

 

# D:\Software\Python2\python.exe E:/Code/Python/MyTestSet/easygui_/filesavebox.py

# E:\Code\Python\MyTestSet\easygui_\newFile.doc

# 当然了,这里仅仅是一个完整的路径加上文件名而已,并不会真的保存成一个文件,保存文件需要用到其他的库

#

# Process finished with exit code 0

Copy after login

exceptionbox

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

# coding:utf-8

 

#  __author__ = 'Mark sinoberg'

#  __date__ = '2016/5/25'

#  __Desc__ = 这是一个很好用的对话框,当应用程序出现异常的时候,就可以通过这个来给与用户友好的界面提示

 

import easygui

 

try:

  int('Exception')

except:

  easygui.exceptionbox('int类型数据转换错误!请检查您的数据类型!')

 

# 会弹出一个界面,内容信息可以自己定义,如上面。下面的内容就是追踪到的出错信息

# Traceback (most recent call last):

#  File "E:/Code/Python/MyTestSet/easygui_/exceptionbox.py", line 10, in <module>

#   int(&#39;Exception&#39;)

# ValueError: invalid literal for int() with base 10: &#39;Exception&#39;

Copy after login

Summary

After reading these examples, you must be very confident in developing simple desktop applets with easygui. (^__^) Hehe...

But, for more complex tasks, just mastering these basics is not enough. So we also need to dig into other related modules of Python. In this way, during actual development, the most appropriate module can be selected for development based on the difficulty of the task.

Thank you for reading, I hope it can help you, thank you for your support of this site!

For more Python module EasyGui detailed introduction and related articles, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1661
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
Python vs. C  : Applications and Use Cases Compared Python vs. C : Applications and Use Cases Compared Apr 12, 2025 am 12:01 AM

Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

Python: Games, GUIs, and More Python: Games, GUIs, and More Apr 13, 2025 am 12:14 AM

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

The 2-Hour Python Plan: A Realistic Approach The 2-Hour Python Plan: A Realistic Approach Apr 11, 2025 am 12:04 AM

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

How Much Python Can You Learn in 2 Hours? How Much Python Can You Learn in 2 Hours? Apr 09, 2025 pm 04:33 PM

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

Python vs. C  : Learning Curves and Ease of Use Python vs. C : Learning Curves and Ease of Use Apr 19, 2025 am 12:20 AM

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

Python and Time: Making the Most of Your Study Time Python and Time: Making the Most of Your Study Time Apr 14, 2025 am 12:02 AM

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python: Exploring Its Primary Applications Python: Exploring Its Primary Applications Apr 10, 2025 am 09:41 AM

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

Python: Automation, Scripting, and Task Management Python: Automation, Scripting, and Task Management Apr 16, 2025 am 12:14 AM

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.

See all articles