zoukankan      html  css  js  c++  java
  • Python学习笔记——GUI

    1. 相关文档

    2. 安装步骤

    ① win+R 打开命令行窗口

    ② 按顺序输入如下代码

    f:

    cd "f:codespythonpythonfishcguieasygui-docs-0.96"

    dir

    python setup.py install

    它安装在 C:Users igream LinAppDataLocalProgramsPythonPython37-32Libsite-packages

    3. 导入gui

    import easygui
    easygui.msgbox('hello world!')
    
    # 导入模块中的所有包
    # 这样,调用方法就不用写模块名
    # 这样可能会导致原程序中的同名方法被覆盖
    from easygui import *
    msgbox('你好!')
    
    # 模块改昵称
    import easygui as g
    g.msgbox('hello world!')
    

    4. 使用Easygui

    import easygui as g
    import sys
    
    while 1:
        g.msgbox("嗨,欢迎进入第一个界面小游戏^ ^")
        msg = "请问你希望在鱼c工作室学习到什么知识呢?"
        title = "小游戏互动"
        choices = ["谈恋爱", "编程","00XX","琴棋书画"]
        choice = g.choicebox(msg, title, choices)
        # note that we convert choice to string, in case
        # the user cancelled the choice, and we got None .
        g.msgbox("你的选择是:" + str(choice), "结果")
        msg = "你希望重新开始小游戏吗?"
        title = "请选择"
        if g.ccbox(msg,title):  # show a Continue/Cancel dialog
            pass  # user chose Continue
        else:
            sys. exit(0)  # user chose Cancel
    

    gui界面

    5. 注意:建议不要在IDLE上运行EasyGUI

    EasyGui是运行在Tkinter上并拥有自身的事件循环,而IDLE也是Tkinter写的一个应用程序并也拥有自身的事件循环。因此当两者同时运行的时候,有可能会发生冲突,且带来不可预测的结果。因此如果你发现你的EasyGui程序有这样的问题,请尝试在IDLE外去运行你的程序。

    6. 修改默认的样式

    默认样式如下图所示:

    默认样式

    修改choicebox控件的宽高

    ① 打开C:Users igream LinAppDataLocalProgramsPythonPython37-32Libsite-packageseasygui.py
    ② ctrl+F搜索 def __choicebox
    ③ 找到 root_width = int((screen_width * 0.8)) 和 root_height = int((screen_height * 0.5))
    ④ 将0.8改为0.4,将0.5改为0.25

    修改字体

    ① 打开C:Users igream LinAppDataLocalProgramsPythonPython37-32Libsite-packageseasygui.py
    ② ctrl+F搜索 PROPORTIONAL_FONT
    ③ 找到 PROPORTIONAL_FONT_FAMILY = ("MS", "Sans", "Serif")
    ④ 将其改为 PROPORTIONAL_FONT_FAMILY = ("微软雅黑")

  • 相关阅读:
    openssl之EVP系列之5---EVP_Encrypt系列函数具体解释(二)
    LINQ to SQL活学活用(1):这要打破旧观念
    【安卓】乾坤大罗移,将容器触摸事件传至还有一容器、!
    高速排序——JAVA实现(图文并茂)
    WebCollector爬取百度搜索引擎样例
    nyist 202 红黑树(二叉树中序遍历)
    excel转换日期格式,将yyyymmdd类型日期转换成yyyy-mm-dd等日期类型方法
    窗体界面设计03
    窗体界面设计02
    窗体界面设计01
  • 原文地址:https://www.cnblogs.com/nigream/p/11251173.html
Copyright © 2011-2022 走看看