Python基础入门学习笔记 035 图形用户界面入门:EasyGui

发布时间 2023-08-23 10:23:36作者: 一杯清酒邀明月

图形用户界面编程,也就是平时常说的GUI(Graphical User  Interface),python有一个非常简单的GUI工具包:EasyGui

GUI的安装

导入方法一:

1 >>> import easygui         #导入EasyGui
2 >>> easygui.msgbox('嗨,亦我飞也')

导入方法二:

1 >>> from easygui import *
2 >>> msgbox('嗨,亦我飞也')

导入方法三(推荐使用):

1 >>> import easygui as g
2 >>> g.msgbox('嗨,亦我飞也')

显示图片(注:图片需要为GIF格式,且存放在python.exe通目录)

>>> easygui.buttonbox(msg='你喜欢以下哪种水果',title='亦我飞也',choices=('草莓','西瓜','芒果'),image='aa.gif')

实例1:

 1 import easygui as g
 2 import sys
 3 
 4 while 1:
 5 g.msgbox("嗨,欢迎进入第一个界面小游戏")
 6 msg = "请问你希望在鱼C工作室学习到什么知识呢"
 7 title="小游戏互动"
 8 choices=["谈恋爱","编程","OOXX","琴棋书画"]
 9 choice=g.choicebox(msg,title,choices)
10 
11 #note that we convert choice to string,in case
12 #the user cancelled the choice,and we got None
13 g.msgbox("你的选择是:"+str(choice),"结果")
14 msg="你希望重新开始小游戏吗?"
15 title=" 请选择"
16 if g.ccbox(msg,title): #show a Contiue/Cancel dialog
17 pass #user chose Contonue
18 else:
19 sys.exit(0) #user chose Cancel

 修改窗口大小(choicebox)

 修改文字大小(PROPORTIONAL_FONT)