python--easygui

1.msgbox

import easygui as eg

# msgbox
# 一般使用三个参数,msg:内容,title:标题,ok_button:按钮内容
eg.msgbox(msg="新垣結衣大好き", title="gakki", ok_button="come on!")

  

2.ccbox

import easygui as eg

# ccbox
# 和msgbox一样,主要用到三个参数
# msg:内容,title:标题,choices:选择项,只能放两个选项。
# 该函数有返回值,如果choices点的是左边的返回True,右边的返回False

if eg.ccbox(msg="我是一只老流氓", title="流氓", choices=("yes", "no")):
    print("是你妹啊是")
else:
    print("这就对了嘛")
    
# 点击yes,执行if
# 点击no,返回False,执行else

  

3.buttonbox

import easygui as eg

# buttonbox

# 参数就不介绍了,这个函数也是有返回值的,你点的哪个,就返回哪个
a = eg.buttonbox(msg="下面哪个是你老婆", title="选老婆", choices=("和泉纱雾", "四方茉莉", "坂上智代"))
print(a)  # 坂上智代

  

 4.indexbox(),和buttonbox()功能一样,区别就是点击第一个返回0,依次类推,而不是返回文字

5.在buttonbox()中显示图片

import easygui as eg

a = eg.buttonbox(msg="我太太可爱吗?", title="我的太太",
             choices=("可爱", "非常可爱", "超级可爱"),
             image=r"C:\Users\Administrator\Desktop\我的太太.jpg")

print(a)  # 超级可爱

  

6.choicebox

import easygui as eg

a = eg.choicebox(msg="你谁啊?", title="who",
                 choices=["哈利波特", "柯南道尔", "阿加莎克里斯蒂", "无人生还"])

print(a)
'''
[0]
阿加莎克里斯蒂
'''

  

7.mutchoicebox

import easygui as eg

a = eg.multchoicebox(msg="你喜欢哪本书", title="book",
                     choices=["东方快车谋杀案", "无人生还", "尼罗河上的惨案", "ABC谋杀案"])

print(a)  # ['东方快车谋杀案', '无人生还', '尼罗河上的惨案', 'ABC谋杀案']

  

 8.enterbox

import easygui as eg

a = eg.enterbox(msg="说出你的心里话", title="心里话",
                strip=True,  # 返回值默认会去除首尾空格
                image=r"C:\Users\Administrator\Desktop\我的太太.jpg")

print(a)  # 我爱新垣结衣

  

9.integerbox

import easygui as eg

a = eg.integerbox(msg="请给我太太的颜值打个分吧", title="打分",
                  lowerbound=1,  # 输入的分数如果不在1到100分之间,会要求重新输入
                  upperbound=100,
                  image=r"C:\Users\Administrator\Desktop\我的太太.jpg")

print(a)  # 100

  

如果不在1到100之间的话

 会报错,让重新输入

10.multenterbox

import easygui as eg

msg = "请输入你太太的个人信息(带*的必填)"
title = "info"
fieldNames = ["*姓名", "身高", "年龄", "*丈夫"]
fieldValues = eg.multenterbox(msg, title, fields=fieldNames)

while 1:
    # 如果用户取消操作
    if fieldValues == None:
        break

    errmsg = ""
    for index in range(len(fieldNames)):
        if fieldValues[index].strip() == "" and fieldNames[index].startswith("*"):
            errmsg += f"{fieldNames[index]}不可以为空"

    if not errmsg:
        break

    # values表示我们预先设置好的填充值,如果用户输入不合法,那么之前输入的不会消失
    fieldValues = eg.multenterbox(errmsg, title, fields=fieldNames, values=fieldValues)

info = {fieldNames[i]: fieldValues[i] for i in range(len(fieldNames))}
print(f"您太太的信息为:{info}")  # 您太太的信息为:{'*姓名': '新垣结衣', '身高': '169', '年龄': '30', '*丈夫': '猪哥哥'}

  

 # 如果带星号的没有填写

11.passwordbox

import easygui as eg

a = eg.passwordbox(msg="请输入您的密码")
print(a)  # 123456

  

12.multpasswordbox

import easygui as eg

# fields可以设置多个,最后一个输入默认是**,一般把最后一个当做密码
# values是我们自动设置好的值
a = eg.multpasswordbox(msg="请输入用户信息", fields=("用户名", "邮箱", "密码"), values=("xxx", "[email protected]", "*****"))
print(a)  # ['新垣结衣', '[email protected]', '123456']

  

 总结:easygui的这些函数,里面的参数都差不多类似。

猜你喜欢

转载自www.cnblogs.com/traditional/p/9434385.html