下载easygui网址:https://sourceforge.net/projects/easygui/files/0.96
打开cmd
切换到d盘下的搜狗高速下载(因为我的easygui放到了此文件夹下)
import easygui as g
g.msgbox('嗨,我傻蛋')
import easygui as g
import sys
while 1:
g.msgbox('嗨,欢迎进入第一个界面小游戏》》》》')
msg='请问您是希望在这里学到什么知识呢?'
title='小游戏互动'
choices=['谈恋爱','编程','琴棋书画','偷懒']
choice=g.choicebox(msg,title,choices)
g.msgbox('你选择的是:'+str(choice),'结果')
msg='你希望重新开始游戏吗?'
title='请选择'
if g.ccbox(msg,title):
pass
else:
sys.exit(0)
中文版的easygui教程:
http://www.360doc.com/content/19/1129/11/541242_876303771.shtml
import easygui as g
import random
secret=random.randint(1,10)
msg='不妨猜一下小甲鱼心里现在想的数字吧(1--10):'
title='数字小游戏'
guess=g.integerbox(msg,title,lowerbound=1,upperbound=10)
while 1:
if secret==guess:
g.msgbox('你是小甲鱼心里的蛔虫吗?')
g.msgbox('hahhhhh,猜对了也没有奖励!')
break
else:
if secret>guess:
g.msgbox('小了')
else:
g.msgbox('大了')
guess=g.integerbox(msg,title,lowerbound=1,upperbound=10)
g.msgbox('游戏结束')
import easygui as g
msg = '请填写以下联系方式'
title = '账号中心'
fieldNames=['*用户名','*真实姓名','固定电话','*手机号码','QQ','*E-mail']
fieldValues=[]
fieldValues=g.multenterbox(msg,title,fieldNames)
while 1:
if fieldValues==None:
break
errmsg=''
for i in range(len(fieldNames)):
option=fieldNames[i].strip()
if fieldValues[i].strip()=='' and option[0]=='*':
errmsg+=('【%s】为必填项。\n' % fieldNames[i])
if errmsg=='':
break
fieldValues=g.multenterbox(errmsg,title,fieldNames,fieldValues)
print('用户资料如下:%s' % str(fieldValues))
import easygui as g
import os
file_path=g.fileopenbox(default='*.txt')
with open(file_path) as f:
#下图有介绍os.path.basename
title=os.path.basename(file_path)
msg='文件【%s】的内容如下:' % title
text = f.read()
g.textbox(msg,title,text)
##没看懂
import easygui as g
import os
# fileopenbox() 函数用于提供一个对话框,返回用户选择的文件名
file_path=g.fileopenbox(default='*.txt')
with open(file_path) as old_f:
#下图有介绍os.path.basename
title=os.path.basename(file_path)
msg='文件【%s】的内容如下:' % title
text = old_f.read()
text_after=g.textbox(msg,title,text)
if text != text_after[:-1]:
# textbox的返回值会追加一个换行符
choice=g.buttonbox('检测到文件内容发生改变,请选择以下操作:','警告',('覆盖保存','放弃保存','另存为...'))
if choice=='覆盖保存':
with open(file_path,'w') as old_f:
old_f.write(text_after[:-1])
if choice=='放弃保存':
pass
if choice=='另存为...':
another_path=g.filesavebox(default='.txt')
if os.path.splitext(another_path)[1] !='.txt':
another_path+='.txt'
with open(another_path,'w') as new_f:
new_f.write(text_after[:-1])