目录:
一、安装GUI工具包:EasyGui
二、导入EasyGui
三、使用EasyGui
四、修改默认设置
五、课时35课后习题及答案
***********************************
一、安装GUI工具包:EasyGui
***********************************
本章介绍的是图形用户界面编程,也就是平时所说的GUI(读作【gu:i】)编程,那些带有按钮、文本、输入框的窗口的编程,相信大伙都不会陌生。
目前有很多Python的GUI工具包可供选择,Python有一个非常简单的GUI工具包:EasyGui。EasyGui跟它的名字一样的简单,一旦你的模块导入了EasyGui,GUI操作就是一个简单地调用EasyGui函数的几个参数的问题了。
EasyGui官网:http://easygui.sourceforge.net
使用标准方法安装:
第一步:解压easygui-0.96.zip
第二步:使用命令窗口切换到easygui-docs-0.96的目录下。
第三步:在windows下执行 C:Python34python.exe setup.py install
在Linux或Mac下执行 sudo /usr/bin/python34 setup.py install
(命令的前面部分是python程序在电脑上的安装路径,自行进行修改)
windows下的安装界面如下图所示:

********************
二、导入EasyGui
********************
为了使用这个Easygui这个模块,你应该先导入它。最简单的导入语句是 import easygui。
如果用这种导入方式的话,那么在使用easygui的函数时候,必须在函数的前面加上前缀easygui:
>>> import easygui >>> easygui.msgbox("DC love ZWW")
回车后即弹出消息框,如图所示:

另一种选择是导入整个Easygui包:from easygui import *,这样使得我们更容易调用Easygui的函数,可以直接这样编写代码:
>>> from easygui import * >>> msgbox("DC love ZWW")
第三种方案是使用类似下边的import语句(建议使用):import easygui as g,这样可以让你保持Easygui的命名空间,同时减少输入字符的数量:
>>> import easygui as g >>> g.msgbox("DC love ZWW")
********************
三、使用EasyGui
********************
举一个简单的例子:

import easygui as g import sys while 1: g.msgbox ("嗨,欢迎进入第一个界面小游戏") msg = "请问你希望学到什么知识呢?" title = "游戏小互动" choices = ["谈恋爱","编程","demo","琴棋书画"] choices = g.choicebox(msg,title,choices) g.msgbox("您的选择是:"+str(choices),"结果") msg = "你希望重新开始小游戏吗?" title = "请选择" if g.ccbox(msg,title): pass else: sys.exit(0)





*********************
四、修改默认设置
*********************
默认情况下显示的对话框会很大,而且字体也相对难看。这里可以手动调整EsayGui的参数修改。
修改位置为 C:Python34Libsite-packageseasygui.py。
更改对话框尺寸:找到def _ _choicebox,下边的 root_width = int((screen_width * 0.8))和 root_height = int((screen_height * 0.5))分别改为root_width = int((screen_width * 0.4))和 root_height = int((screen_height * 0.25))
EasyGui提供了非常多的组件供我们实现一个完整的界面程序,刚才演示了 msgbox、choicebox和ccbox的用法。关于更多的组建使用,大家可以参考小甲鱼翻译的《EasyGui学习文档》:http://bbs.fishc.com/thread-46069-1-1.html
*******************************
五、课时35课后习题及答案
*******************************
















