zoukankan      html  css  js  c++  java
  • EasyGui

    EasyGui

    在IDLE上运行EasyGui可能存在冲突

    EasyGui是运行在Tkinter上并哟拥有自身的事件循环,而IDLE也是Tkinter写的一个应用程序并页拥有自身的事件循环。两者同时运行,有可能会发生冲突,且带来不可预测的结果。

    运行EasyGui演示程序

    1.命令行中执行

    python.exe easygui.py

    2.从IDLE等上来调用

    >>> import easygui as g
    >>> g.egdemo()

    EasyGui的导入方式

    方法1

    import easygui
    easygui.msgbox(...)

    方法2

    from easygui import *
    msgbox(...)

    方法3

    import easygui as g
    g.msgbox(...)

    EasyGui()的默认参数

    msgbox()函数标题部分,参数可选,只指定内容,不指定标题:

    import easygui as g
    g.msgbox('Hello, world!')

    指定标题参数和消息

    from easygui import *
    msgbox('Hello, World!','我是标题呀!= =')

    绝大部分的EasyGui函数都有默认参数,几乎所有的组件都会显示一个消息和标题。标题默认是空字符串,信息通常有一个简单的默认值。

    EasyGui()使用关键字参数

    from easygui import *
    choices = ['喜欢','很喜欢','非常喜欢']
    reply = choicebox('你喜欢我吗?', choices = choices)

    使用按钮组件

    EasyGui在buttonbox()上建立了一系列的函数供调用

    • msgbox()

    msgbox(msg = ”, title = ”, ok_button = ‘OK’, image = None, root = None)

    msgbox()显示一个消息和提供一个‘OK’按钮,消息、标题和‘OK’按钮都可指定。

    from easygui import *
    msgbox('你好美~',ok_button = '这不是废话吗?')


    • ccbox()

    ccbox(msg = ‘continue?’, title = ”, choices = (‘choice1’, ‘choice2’), image = None)

    ccbox()提供一个选择:Continue或者Cancel, 并相应的返回1(选中Continue)或者0(选中Cancel)。

    注意:ccbox()是返回整型的1或0,不是布尔型的True或False。

    import sys
    from easygui import *
    if ccbox('和我交往吗?', choices = ('不要,你长得太丑了~','算了吧,要找个比你更好看的~')):
        msgbox('那我们绝交吧!哼~')
    else:
        sys.exit(0)

    点击第一个,弹出另一弹窗;点击第二个关闭窗口。


    • ynbox()

    作用同上!!!

    ynbox(msg = ‘continue?’, title = ”, choices = (‘choice1’, ‘choice2’), image = None)


    • buttonbox()

    buttonbox(msg = ”, title = ”, choices = (‘Button1’, ‘Button2’, ‘Button3’), image = None, root = None)

    可使用buttonbox() 定义自己的一组按钮

    当用户点击按钮时,buttonbox()返回按钮的文本内容。如果用户取消或者关闭窗口,那么会返回默认选项(第一个选项)。

    from easygui import *
    buttonbox(msg = '你叫什么名字?', choices = ('小花', '小芳', '小明'))


    • indexbox()

    indexbox(msg = ‘continue?’, title = ”, choices = (‘Yes’, ‘No’), image = None)

    和上面差不多,区别在于,当用户选择第一个按钮时返回序号0,选择第二个按钮时返回序号1.


    • boolbox()

    boolbox(msg = ‘continue?’, title = ”, choices = (‘Yes’, ‘No’), image = None)

    如果第一个按钮被选中返回1,否则返回0.


    • buttonbox中显示图片

    当调用buttonbox 函数(例如:msgbox(), ynbox(), indexbox() 等等)的时候,还可以为关键字参数image赋值。

    注意:仅支持GIF格式!!!

    import easygui as g
    g.buttonbox("喂喂喂,你是谁?",image = r'C:UsersmengtianDesktop9.jpg', choices = ('小白', '小黄', '小绿'))

    多选框

    • choicebox()

    choicebox(msg = ‘Pick something’, title = ”, choices = ())

    提供可选择的列表,使用序列(元组或列表)作为选项,这些选项显示前会按照不区分大小写的方法排好序。

    from easygui import *
    
    choices = ['喜欢','很喜欢','非常喜欢', '以上答案都是,/(ㄒoㄒ)/~~']
    choicebox(msg = '你喜欢编程吗?', title = '大胆说出你真心话!', choices = choices)


    • multchoicebox()

    multchoicebox(msg = ‘many items’, title = ”, choices = (), **kwargs)

    提供一个可选择的列表,与choicebox()不同的是,multchoicebox()支持用户选择0个,1个或者同事选择多个选项。

    函数页是使用序列(元组或列表)作为选项,这些选项显示前会按照不区分大小写的方法排好序。

    返回值为,选择项组成的列表(无选择项时,列表为空)。

    from easygui import *
    
    choices = ['喜欢','很喜欢','非常喜欢', '喜欢得不得了']
    multchoicebox(msg = '你喜欢编程吗?', title = '大胆说出来', choices = choices)

    用户输入

    • enterbox()

    enterbox(msg = ‘enter something.’, title = ”, default = ”, strip = True, image = None, root =None)

    提供简单的输入框,返回值为用户输入的字符串。默认返回的值会自动去除首尾的空格,如果需要保留首尾空格,设置参数strip=False。

    其中,参数default为输入框默认显示值。

    from easygui import *
    
    enterbox(msg = '说出你想对Shirley说的话:',title = '你说,说呀!',default = '你真美~',strip = None)


    • integerbox()

    integerbox(msg = ”, title = ”, default = ”, lowerbound = 0, upperbound = 99, image = None, root = None, **invalidKeywordArguments)

    为用户提供一个简单的输入框,用户只能输入范围内(lowerbound参数设置最小值,upperbound参数设置最大值)的整型数值 ,否则会要求用户重新输入。

    输入的为int型。

    from easygui import *
    
    integerbox(msg = '说出你想对Shirley说的话:',title = '老实交代~',default = 5 ,lowerbound = 0, upperbound=5,root=None)


    • multenterbox()

    multenterbox(mag = ‘Fill in values for the fields.’, title = ”, fields = (), values = ())

    提供多个简单的输入框,注意:

    1.如果用户输入的值比选项少,则返回列表中的值用空字符串填充用户为输入的选项;

    2.如果用户输入的值比选项多,则返回列表中的值将截断为选项的数量;

    3.如果用户取消操作,则返回域中的列表的值或者None值;

    from easygui import *
    
    fields_list = ['*用户名','*手机号','QQ','*E-mail']
    values_list = ['Shirley','','','']
    multenterbox(msg = '带*号的为必填项', title = '123', fields = fields_list, values = values_list)

    用户密码输入

    • passwordbox()

    passwordbox(msg = ‘Enter your password.’, title = ”, default = ”, image = None, root = None)

    passwordbox()跟enterbox()样式一样,不同的是用户输入的内容用”*“显示出来,返回用户输入的字符串。

    from easygui import *
    
    passwordbox(msg = '请输入密码', title = '密码输入')


    • multpasswordbox()

    multpasswordbox(msg = ‘Fill in values for the fields.’, title = ”,fields = (), values = ())

    from easygui import *
    
    multpasswordbox(msg = '请输入用户名和密码', title = '登录',fields = ('用户名:','密码'), values = ('Shirley',))

    显示文本

    • textbox()

    textbox(msg = ”, title = ”, text = ”, codebox = 0)

    函数默认会以比例字体(参数codebox = 1设置为等宽字体)来显示文本内容(会自动换行),这个函数适合用于显示一般的书面文字。

    参数text可以是字符串类型,列表类型,或者元组类型。

    from easygui import *
    
    text = """
    从明天起,做一个幸福的人
    喂马,劈柴,周游世界
    从明天起,关心粮食和蔬菜
    我有一所房子,面朝大海,春暖花开
    从明天起,和每一个亲人通信
    告诉他们我的幸福
    那幸福的闪电告诉我的
    我将告诉每一个人
    给每一条河每一座山取一个温暖的名字
    陌生人,我也为你祝福
    愿你有一个灿烂的前程
    愿你有情人终成眷属
    愿你在尘世获得幸福
    我只愿面朝大海,春暖花开
    """
    textbox(msg = '文本内容如下:', title = '文本文件', text = text, codebox = 1)


    • codebox()

    codebox(msg = ”, title = ”, text = ”)

    以等宽字体显示文本内容,相当于textbox(codebox=1)

    目录与文件

    当需要用户输入目录及文件名的时候,需要有浏览文件系统,让用户选择

    • diropenbox()

    diropenbox(msg = None, title = None, default = None)

    用于提供一个对话框,返回用户选择的目录名(完整路径),如果用户选择“Cancel”则返回None。

    default参数用于设置默认的打开目录(需是存在的目录)

    from easygui import *
    
    diropenbox(msg = '请选择文件:',title = '浏览文件')


    • fileopenbox()

    fileopenbox(msg = None, title = None, default = ‘*’, filetypes = None)

    用于提供一个对话框,返回用户选择的文件名,如果用户选择”Cancel“则返回None。

    default参数,设置默认路径,通常包含一个或多个通配符;default默认的参数是“*”,即匹配所有格式的文件。

    filetypes参数,可以为包含文件掩码的字符串列表,也可以是字符串列表,列表的最后一项字符串是文件类型的描叙。

    from easygui import *
    
    fileopenbox(msg = '请选择文件:',title = '浏览文件')

    • filesavebox()

    filesavebox(msg = None, title = None, default = ”, filetypes = None)

    提供一个对话框,用于选择文件需要保存的路径(完整路径),如果用户选择”Cancel“则返回None。

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

    filetypes参数,可以为包含文件掩码的字符串列表,也可以是字符串列表,列表的最后一项字符串是文件类型的描叙。

  • 相关阅读:
    Linux命令应用大词典-第11章 Shell编程
    Kubernetes 学习12 kubernetes 存储卷
    linux dd命令
    Kubernetes 学习11 kubernetes ingress及ingress controller
    Kubernetes 学习10 Service资源
    Kubernetes 学习9 Pod控制器
    Kubernetes 学习8 Pod控制器
    Kubernetes 学习7 Pod控制器应用进阶2
    Kubernetes 学习6 Pod控制器应用进阶
    Kubernetes 学习5 kubernetes资源清单定义入门
  • 原文地址:https://www.cnblogs.com/guoyunlong666/p/9440144.html
Copyright © 2011-2022 走看看