1.利用msgbox(单词messagebox的缩写)给出一个提示信息:html
import easygui as g reply=g.msgbox('This is a basic message box.', 'Title Goes Here') print(reply) #http://easygui.sourceforge.net/
运行结果:ide
import easygui easygui.msgbox('Hello, world!')
运行结果:函数
说明:easygui.msgbox('Hello, world!')这一句有个返回值,就是字符'OK'。这个特色是:只能点击OK,返回值肯定。
利用ynbox给出yes or no 对话框:
import easygui as g reply=g.ynbox('Shall I continue?', 'Title', ('Yes', 'No')) print(reply) #http://easygui.sourceforge.net/
运行结果:学习
说明:点'Yes',返回True,点'No',返回False。
导入easygui时起个别名:
import easygui easygui.msgbox('Hello EasyGui!') #可是,直接使用import导入,以后使用其中的方法时须要加上easygui的前缀,例如easygui.msgbox()。这样比较麻烦,咱们还能够选择导入整个EasyGui的包: from easygui import * msgbox('Hello EasyGui!') #上面的方法效果时同样的。咱们还有第三种方法: import easygui as g g.msgbox('Hello EasyGui!') #这个方法的好处是保留了EasyGui的命名空间,且调用时不用写出完整的包名。同时避免了第二种方法致使的函数覆盖的可能
#https://www.zybuluo.com/kingwhite/note/128328
2.给出一个提示信息,而且OK按钮的内容能够更改:ui
from easygui import * msgbox('您选的序号是未知序号!',ok_button = '关闭程序')
和第一个同样,返回值是字符串,只是出现的返回值的内容能够修改。.net
3.打开文件对话框:3d
import easygui path = easygui.fileopenbox()
若是选择打开文件,则返回值是所打开文件的全路径,若是选择取消,则返回'None'。htm
4.选择多个字符串列表中的某个字符串,并返回显示在对话框上面:blog
import easygui as g import sys while True: g.msgbox('嗨,欢迎进入第一个GUI制做的小游戏~') msg = '你但愿学习到什么知识呢?' title = '互动小游戏' choices = ['琴棋书画', '四书五经', '程序编写', '逆向分析'] choice = g.choicebox(msg, title, choices) # note that we convert the choice to string, in case the user # cancelled the choice, and we got None. g.msgbox('你的选择是:' + str(choice), '结果') msg = '你但愿从新开始小游戏么?' title = '请选择' if g.ccbox(msg, title): # Show a Continue/Cancel dialog pass # user choose Continue else: sys.exit(0) # user choose Cancel
5.和4类似的例子:游戏
import easygui as g import sys while 1: g.msgbox("Hello, world!") msg ="What is your favorite flavor?" title = "Ice Cream Survey" choices = ["Vanilla", "Chocolate", "Strawberry", "Rocky Road"] choice = g.choicebox(msg, title, choices) # note that we convert choice to string, in case # the user cancelled the choice, and we got None. g.msgbox("You chose: " + str(choice), "Survey Result") msg = "Do you want to continue?" title = "Please Confirm" if g.ccbox(msg, title): # show a Continue/Cancel dialog pass # user chose Continue else: sys.exit(0) # user chose Cancel #http://easygui.sourceforge.net/tutorial.html
6.easygui的buttonbox:
import easygui as g reply=g.buttonbox('Click on your favorite flavor.', 'Favorite Flavor', ('Chocolate', 'Vanilla', 'Strawberry')) print(reply) #http://easygui.sourceforge.net/
7.返回选择的文件夹的名字:
import easygui as g reply=g.diropenbox() print(reply)
运行结果:
8.另存为对话框:
import easygui as g reply=g.filesavebox() print(reply)
9.输入内容对话框:
import easygui as g reply=g.enterbox("shuru:") print(reply)