search
HomeBackend DevelopmentPython TutorialDetailed introduction to Python module EasyGui

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

# 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)

bottonbox

# 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)

choicebox

# 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)

enterbox

# coding:utf-8

#  __author__ = 'Mark sinoberg'
#  __date__ = '2016/5/25'
#  __Desc__ = 可以满足用户输入的控件

import easygui

st = easygui.enterbox("请输入一段文字:\n")
print "您输入了: " + str(st)

mutilchoicebox

# 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

intenterbox,passenterbox

# 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

textbox,codebox

# 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

diropenbox

# 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

fileopenbox

# 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

filesavebox

# 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

exceptionbox

# 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;

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
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
Are Python lists dynamic arrays or linked lists under the hood?Are Python lists dynamic arrays or linked lists under the hood?May 07, 2025 am 12:16 AM

Pythonlistsareimplementedasdynamicarrays,notlinkedlists.1)Theyarestoredincontiguousmemoryblocks,whichmayrequirereallocationwhenappendingitems,impactingperformance.2)Linkedlistswouldofferefficientinsertions/deletionsbutslowerindexedaccess,leadingPytho

How do you remove elements from a Python list?How do you remove elements from a Python list?May 07, 2025 am 12:15 AM

Pythonoffersfourmainmethodstoremoveelementsfromalist:1)remove(value)removesthefirstoccurrenceofavalue,2)pop(index)removesandreturnsanelementataspecifiedindex,3)delstatementremoveselementsbyindexorslice,and4)clear()removesallitemsfromthelist.Eachmetho

What should you check if you get a 'Permission denied' error when trying to run a script?What should you check if you get a 'Permission denied' error when trying to run a script?May 07, 2025 am 12:12 AM

Toresolvea"Permissiondenied"errorwhenrunningascript,followthesesteps:1)Checkandadjustthescript'spermissionsusingchmod xmyscript.shtomakeitexecutable.2)Ensurethescriptislocatedinadirectorywhereyouhavewritepermissions,suchasyourhomedirectory.

How are arrays used in image processing with Python?How are arrays used in image processing with Python?May 07, 2025 am 12:04 AM

ArraysarecrucialinPythonimageprocessingastheyenableefficientmanipulationandanalysisofimagedata.1)ImagesareconvertedtoNumPyarrays,withgrayscaleimagesas2Darraysandcolorimagesas3Darrays.2)Arraysallowforvectorizedoperations,enablingfastadjustmentslikebri

For what types of operations are arrays significantly faster than lists?For what types of operations are arrays significantly faster than lists?May 07, 2025 am 12:01 AM

Arraysaresignificantlyfasterthanlistsforoperationsbenefitingfromdirectmemoryaccessandfixed-sizestructures.1)Accessingelements:Arraysprovideconstant-timeaccessduetocontiguousmemorystorage.2)Iteration:Arraysleveragecachelocalityforfasteriteration.3)Mem

Explain the performance differences in element-wise operations between lists and arrays.Explain the performance differences in element-wise operations between lists and arrays.May 06, 2025 am 12:15 AM

Arraysarebetterforelement-wiseoperationsduetofasteraccessandoptimizedimplementations.1)Arrayshavecontiguousmemoryfordirectaccess,enhancingperformance.2)Listsareflexiblebutslowerduetopotentialdynamicresizing.3)Forlargedatasets,arrays,especiallywithlib

How can you perform mathematical operations on entire NumPy arrays efficiently?How can you perform mathematical operations on entire NumPy arrays efficiently?May 06, 2025 am 12:15 AM

Mathematical operations of the entire array in NumPy can be efficiently implemented through vectorized operations. 1) Use simple operators such as addition (arr 2) to perform operations on arrays. 2) NumPy uses the underlying C language library, which improves the computing speed. 3) You can perform complex operations such as multiplication, division, and exponents. 4) Pay attention to broadcast operations to ensure that the array shape is compatible. 5) Using NumPy functions such as np.sum() can significantly improve performance.

How do you insert elements into a Python array?How do you insert elements into a Python array?May 06, 2025 am 12:14 AM

In Python, there are two main methods for inserting elements into a list: 1) Using the insert(index, value) method, you can insert elements at the specified index, but inserting at the beginning of a large list is inefficient; 2) Using the append(value) method, add elements at the end of the list, which is highly efficient. For large lists, it is recommended to use append() or consider using deque or NumPy arrays to optimize performance.

See all articles

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

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)