01_msgbox
# 使用easygui功能,可以直接導入easygui模塊
import easygui
# 需要彈框時,要使用easygui。
# msgbox(m)方法,輸出帶有m內容的信息框。
# msg = message 。
easygui.msgbox('你好,我是easygui模塊。')
easygui.msgbox('今天也是充滿希望的一天!')
# easygui.msgbox(m,t,b)有三個參數(shù)。
# m是顯示的信息messag,t是信息框的標題tittle,b是信息框的按鈕button。
easygui.msgbox('請問你做好準備了嗎?','Problem','沖沖沖')
運行結果:

02_ccbox
# 使用easygui功能,也可以直接導入整個easygui包
from easygui import *
msgbox('你好,我是easygui包。')
# ccbox(m,t)方法,可以在選擇框中設置兩個按鈕
# 選擇框的默認按鈕是continue和cancel
# ccbox(m,t,c)方法,可以修改選擇框continue和cancel的按鈕信息
ccbox('請問你做好準備了嗎?','Problem')
ccbox('請問你做好準備了嗎???','再問一遍!',['yes','no'])
運行結果:

04_choicebox
import easygui as g
g.msgbox('你好!')
# g.chociebox(m,t,b)方法,可以設置多個選項
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()方法,可以設置按鈕變量,可以插入圖片。
g.buttonbox('你看胡偉成長的帥嗎?','靈魂發(fā)問',['帥!','不帥!','emm'],image='hwc1024.jpg')
運行結果:

06_multchoicebox
import easygui as g
# g.multchoicebox()方法,可以定義多選框
c = ['周一','周二','周三','周四','周五','周六','周天']
reply = g.multchoicebox('一周中哪幾天有課?','Problem',c)
prompt = '一周中'+str(reply)+'有課'
g.msgbox(prompt)
運行結果:

07_enterbox
import easygui as g
# g.enterbox()方法,文本輸入框。
reply = g.enterbox('你愛我嗎?','靈魂發(fā)問')
prompt = '您的回答是:'+reply+'\n\n謝謝你!'
g.msgbox(prompt)
運行結果:

08_multenterbox
import easygui as g
m = '輸入賬號注冊信息:\n\n\n'
t = '注冊系統(tǒng)'
f = ['用戶名','密碼','電話']
# g.multenterbox方法,可以定義一個多輸入框
# fields選項,是與每行輸入對應的題目
# 遇到復雜的easygui,通過定義‘變量名=變量屬性值'的方法更加簡潔
g.multenterbox(msg=m,title=t,fields=f)
運行結果:

09_passwordbox
import easygui as g
# g.passwordbox方法,可以定義密碼輸入框
# 對于密碼的輸入字符,將會被***符合掩蓋
g.passwordbox('請輸入密碼:','登陸系統(tǒng)')
運行結果:

10_multpasswordbox
import easygui as g
# g.multpasswordbox方法,可以定義多行密碼輸入框
# 只有密碼在最后一行被輸入時,才會被***符合掩蓋
m = '請輸入您的賬號注冊信息:'
t = '賬號注冊系統(tǒng)'
f = ['用戶名','電話','郵箱','密碼']
g.multpasswordbox(msg=m,title=t,fields=f)
運行結果:

11_textbox
import easygui as g
# g.textbox方法,可以定義一個文本輸出框
# 其中的text變量可以定義為待輸出的文本
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
# g.diropenbox方法,可以定義一個文件選擇框
# 返回的數(shù)據(jù)是選擇的文件名及路徑
# diropenbox方法,可以選擇文件夾
direction = g.diropenbox()
g.msgbox(direction)
13_fileopenbox
import easygui as g
# g.fileopenbox方法,類似于diropenbox方法。
# fileopenbox方法,只能選擇文件,不能選擇文件夾
direction = g.fileopenbox()
g.msgbox(direction)
14_filesavebox
import easygui as g
import os
# 在fileopen方法中設置default,可以篩選文件類型,例如'*.txt'
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:
# textbox方法的返回值會追加一個空行
reply = g.buttonbox('檢測到文件發(fā)生改變,請選擇操作:',choices=['覆蓋保存','不保存','另存為..'])
if reply=='覆蓋保存':
with open(direction,'w',encoding='utf-8') as file2:
file2.write(tb)
elif reply=='另存為..':
# g.filesavebox方法,可以返回目標路徑,同樣可以設置default值
file_site = g.filesavebox(default='*.txt')
with open(file_site,'w',encoding='utf-8') as file3:
file3.write(tb)
file.close()
到此這篇關于基于Python的EasyGUI學習實踐的文章就介紹到這了,更多相關Python EasyGUI內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- python GUI庫圖形界面開發(fā)之PyQt5打開保存對話框QFileDialog詳細使用方法與實例
- python GUI庫圖形界面開發(fā)之PyQt5輸入對話框QInputDialog詳細使用方法與實例
- 基于wxPython的GUI實現(xiàn)輸入對話框(2)
- 基于wxPython的GUI實現(xiàn)輸入對話框(1)
- Python GUI之如何使用tkinter控件
- python制作的天氣預報小工具(gui界面)
- python 制作一個gui界面的翻譯工具
- 七個Python必備的GUI庫
- python之PyAutoGui教你做個自動腳本計算器的方法
- Python基礎學習之奇異的GUI對話框