Python学习笔记——GUI

1. 相关文档

2. 安装步骤

① win+R 打开命令行窗口

② 按顺序输入如下代码

f:

cd "f:\codes\python\python\fishc\gui\easygui-docs-0.96"

dir

python setup.py install

它安装在 C:\Users\nigream Lin\AppData\Local\Programs\Python\Python37-32\Lib\site-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\nigream Lin\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\easygui.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\nigream Lin\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\easygui.py
② ctrl+F搜索 PROPORTIONAL_FONT
③ 找到 PROPORTIONAL_FONT_FAMILY = ("MS", "Sans", "Serif")
④ 将其改为 PROPORTIONAL_FONT_FAMILY = ("微软雅黑")

猜你喜欢

转载自www.cnblogs.com/nigream/p/11251173.html