1.三种导入的方法
①直接导入
②导入Gui包
③取代导入
2.使用EasyGui : import easygui as g
①msgbox:g.msgbox(msg = ' 消息 ' , title = ' 标题 ' )
②ccbox:if g.ccbox():
pass
esle:
return
ccbox(msg = 'shall I contine?' , title = ' ' ,choices = ' comtine , canle',image = None)
③choicebox:(' ' , [ ] )
④buttonbox:按钮组件
g.buttonbox(msg = ' ',title = ' ',choice = ( '1' , '2'))
⑤indexbox:g.indexbox(msg = 'shall I continue?' , title = ' ',choices = ('Yes', 'NO'))
⑥boolbox:g.boolbox('shall i continue?' , title = ' ',choices = ('Yes','NO'))
⑦添加图片:buttonbox(msg, img =' .gif ',chioces = ('Yes','NO'))
⑧enterbox:g.enterbox(msg , title , default , strip = True (去掉首尾空格) , image = none , root = none )
⑨interbox:g.interbox(msg , title , defalut , strip = True (去掉首尾空格) ,upperbound = 99(若用户输入不在0~99,则重输))
⑩multenterbox:g.mutenterbox(msg , fileld = () , values = () )
①填入密码:passwordbox(msg = 'Enter your password ' , title = ' ', defalut = ' ' )
multpassworabox(msg , title = ' ' , filed = () , values = () )
②显示文本:textbox(msg = ' ' , title = ' ' , text = '字符串,列表,元组' , codebox = 0(比例字体))当为1:等宽字体(丑)
③目录与文件:diropenbox(msg , title , defalut = none)
fileopenbox(msg , title , defalut = 'C:/fishc/*. py' , filetypes = ' ' )
filesavebox(msg , title , defalut = ' ' , filetypes = none)保存一个文件名和文件类型
④ 捕获异常:exceptionbox() 调出一个显示错误的界面
3.送上一个界面游戏代码
import easygui as g import sys while 1: g.msgbox("嗨,欢迎进入第一个界面小游戏^_^","小蝌蚪找爸爸") msg ="有人说小派是你爸爸??" title = "小游戏互动" choices = ["不是,我爸没有那么帅","是,就是他"] choice = g.buttonbox(msg, title, choices) g.msgbox("好啦好啦不闹啦!","进入下一环节") msg = "这两个姑娘好看不?" image = '//wx2.sinaimg.cn/mw600/aeb19806gy1fif50updl2j20u00u0ju6.jpg' choices = ["beautiful", "ugly"] g.enterbox('你想对她说些什么?','色狼',defalut = '',strip = True) g.integerbox('请输入你的幸运数字!',defalut = '') g.msgbox('经过我严密的计算,十年后你肯定会结婚.') g.buttonbox(msg,image,choices) msg = "你希望重新开始小游戏吗?" title = "请选择" if g.ccbox(msg, title): # show a Continue/Cancel dialog g.msgbox("滚,没有啦!不玩啦!","被骗了吧,嘻嘻") # user chose Continue sys.exit(0) else: g.msgbox("你真的要不玩了吗@_@","伤心") g.msgbox("那拜拜,贱人!!","慢走") sys.exit(0)