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)