基于Python的EasyGUI学习
01_msgbox
import easygui
easygui.msgbox('你好,我是easygui模块。')
easygui.msgbox('今天也是充满希望的一天!')
easygui.msgbox('请问你做好准备了吗?','Problem','冲冲冲')
运行结果:
02_ccbox
from easygui import *
msgbox('你好,我是easygui包。')
ccbox('请问你做好准备了吗?','Problem')
ccbox('请问你做好准备了吗???','再问一遍!',['yes','no'])
运行结果:
04_choicebox
import easygui as g
g.msgbox('你好!')
reply =g.choicebox('今天也是充满希望的一天。\n\n请问你做好准备了吗?','Problem',['yes','no','emm'])
if reply=='yes':
g.msgbox('您的回答是:'+reply+'\n\n真棒!')
elif reply=='no':
g.msgbox('您的回答是:',+reply+'\n\n抓紧振作起来!')
else:
g.msgbox('快做决定吧别墨迹了!')
运行结果:
05_image
import easygui as g
g.buttonbox('你看胡伟成长的帅吗?','灵魂发问',['帅!','不帅!','emm'],image='hwc1024.jpg')
运行结果:
06_multchoicebox
import easygui as g
c = ['周一','周二','周三','周四','周五','周六','周天']
reply = g.multchoicebox('一周中哪几天有课?','Problem',c)
prompt = '一周中'+str(reply)+'有课'
g.msgbox(prompt)
运行结果:
07_enterbox
import easygui as g
reply = g.enterbox('你爱我吗?','灵魂发问')
prompt = '您的回答是:'+reply+'\n\n谢谢你!'
g.msgbox(prompt)
运行结果:
08_multenterbox
import easygui as g
m = '输入账号注册信息:\n\n\n'
t = '注册系统'
f = ['用户名','密码','电话']
g.multenterbox(msg=m,title=t,fields=f)
运行结果:
09_passwordbox
import easygui as g
g.passwordbox('请输入密码:','登陆系统')
运行结果:
10_multpasswordbox
import easygui as g
m = '请输入您的账号注册信息:'
t = '账号注册系统'
f = ['用户名','电话','邮箱','密码']
g.multpasswordbox(msg=m,title=t,fields=f)
运行结果:
11_textbox
import easygui as g
file_name = g.enterbox('请输入文件名:')
m = '文件'+file_name+'的内容如下:'
t = 'textbox'
file = open(file_name,encoding='utf-8')
g.textbox(msg=m,title=t,text=file.read())
file.close()
运行结果:
12_diropenbox
import easygui as g
direction = g.diropenbox()
g.msgbox(direction)
13_fileopenbox
import easygui as g
direction = g.fileopenbox()
g.msgbox(direction)
16_filesavebox
import easygui as g
import os
direction = g.fileopenbox(default='*.txt')
file = open(direction,encoding='utf-8')
m = '文件'+direction+'的内容如下:'
t = '打开文件'
te = file.read()
tb = g.textbox(msg=m,title=t,text=te)
if te!=tb:
reply = g.buttonbox('检测到文件发生改变,请选择操作:',choices=['覆盖保存','不保存','另存为..'])
if reply=='覆盖保存':
with open(direction,'w',encoding='utf-8') as file2:
file2.write(tb)
elif reply=='另存为..':
file_site = g.filesavebox(default='*.txt')
with open(file_site,'w',encoding='utf-8') as file3:
file3.write(tb)
file.close()