easygui的简单操作

图形用户界面-EasyGui
下载easygui模块,将easygui.py导入到python安转目录下
导入模块
import easygui
import easygui as g
from easygui import *
可以运行easygui的demo
g.egdemo()

EasyGui函数的默认参数
对于所有函数,前两个参数是消息和标题。有固定默认值,title默认是空,msg消息根据特定函数有默认值.根据这些特点,可以调用组建的时候使用关键字调用EasyGui函数

按钮组件
消息按钮
msgbox(msg='(Your message goes here)', title=' ', ok_button='OK', image=None, root=None)
显示一个消息和一个按钮

选择按钮1
ccbox(msg='Shall I continue?', title=' ', choices=('Continue', 'Cancel'), image=None)
当选则第一个选项的时候返回1,选择第二个的时候返回0,默认choices是continue和cancel可以设置

选择按钮2
ynbox(msg='Shall I continue?', title=' ', choices=('Yes', 'No'), image=None)
同样是提供选择,与上面的一样,只是默认值不一样

选择按钮3
用户可以使用列表自定义一组自己的按钮,当选择相应的按钮后会返回按钮内容,当关闭按钮或取消返回第一个
buttonbox(msg='', title=' ', choices=('Button1', 'Button2', 'Button3'), image=None, root=None)

选择按钮4
indexbox(msg='Shall I continue?', title=' ', choices=('Yes', 'No'), image=None)
同上,只是返回其选项的下标,从0开始

选择按钮5
boolbox(msg='Shall I continue?', title=' ', choices=('Yes', 'No'), image=None)
选择第一个返回1,否则返回0.默认第一个

为buttonbox函数(msgbox(),ccbox(),ynbox(),indexbox()等)添加图片,只支持.gif

为用户提供列表选项
choicebox(msg='Pick something.', title=' ', choices=())
提供一个列表的选项,返回选择内容

多列表选项
multchoicebox(msg='Pick as many items as you like.', title=' ', choices=(), **kwargs)
可以同时选择多个项,返回一个列表

让用户输入信息
enterbox(msg='Enter something.', title=' ', default='', strip=True, image=None, root=None)

让用户输入整型数字,有限制
integerbox(msg='', title=' ', default='', lowerbound=0, upperbound=99, image=None, root=None, **invalidKeywordArguments)
lowerbound最低,upperbound最高,否则报错

给用户提供多组输入框
multenterbox(msg='Fill in values for the fields.', title=' ', fields=(), values=())
如果输入小于给出的项则为空串,最后返回一个列表

让用户输入密码
passwordbox(msg='Enter your password.', title=' ', default='', image=None, root=None)

提供用户多组输入,最后一组是密码框
multpasswordbox(msg='Fill in values for the fields.', title=' ', fields=(), values=())
功能与multenterbox()一样

显示文本
以比例字体显示内容
textbox(msg='', title=' ', text='', codebox=0)
可供输入,返回最后文本框的内容.

显示文本
以等框字体显示文本内容
codebox(msg='', title=' ', text='')
返回文本内容

选择路径
diropenbox(msg=None, title=None, default=None)
不选择,返回空。默认值,为打开后默认文件目录

提供一个对话框,返回用户选择的文件名
fileopenbox(msg=None, title=None, default='*', filetypes=None)
这个返回的是文件路径
关于 default 参数的设置方法:

 

   default 参数指定一个默认路径,通常包含一个或多个通配符。
    如果设置了 default 参数,fileopenbox() 显示默认的文件路径和格式。
    default 默认的参数是'*',即匹配所有格式的文件。


例如:

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


关于 filetypes 参数的设置方法:

    可以是包含文件掩码的字符串列表,例如:filetypes = ["*.txt"]
    可以是字符串列表,列表的最后一项字符串是文件类型的描述,例如:filetypes = ["*.css", ["*.htm", "*.html", "HTML files"]]

保存文件目录
filesavebox(msg=None, title=None, default='', filetypes=None)
参数和上面相似,返回存储路径
上面的内容转载自:  http://blog.sina.com.cn/s/blog_a36d34240102v761.html
下面是我自己写实例,可以参考着学习
import easygui as g

t = g.buttonbox(msg='你喜欢我吗', choices=('喜欢', '好喜欢', '爱'))
print(t)  # t为你选择的内容

#t1 = g.buttonbox(msg='她好看吗',image='1.jpg',choices=('好看','非常好看'))
#print(t1)

c =g.choicebox(msg='请选择:',choices=('1','2','3'))
print(c)

m = g.multchoicebox(msg='你喜欢那个女明星',title='女神大战',choices=('迪丽热巴','新垣结衣','北川景子'))
print(m)

e = g.enterbox(msg='你想对我说些什么',title='哈哈',strip=True)
print(e)
p = g.passwordbox(msg='enetr your pwd:',root=None)
print(p)

m1 = g.multenterbox(msg='[*真实姓名]为必填项\n[*手机号码]为必填项\n[*E-mail]为必填项\n',\
                    fields=('*用户名','*真实姓名','固定电话','*手机号码','*QQ','E-mail'))
print(m1)

f = g.fileopenbox(msg='打开文件',default='E:/app/python36')

 

posted @ 2017-08-14 17:47  yatolk  阅读(2091)  评论(0编辑  收藏  举报