python tkinter的消息框模塊(messagebox,simpledialog)
tkinter提供了三個(gè)模塊,可以創(chuàng)建彈出對(duì)話窗口:(使用必須單獨(dú)導(dǎo)入模塊)
1.messagebox 消息對(duì)話框
示例:askokcancel
import tkinter # 導(dǎo)入消息對(duì)話框子模塊 import tkinter.messagebox # 創(chuàng)建主窗口 root = tkinter.Tk() # 設(shè)置窗口大小 root.minsize(300,300) # 聲明函數(shù) def okqqq(): # 彈出對(duì)話框 result = tkinter.messagebox.askokcancel(title = '標(biāo)題~',message='內(nèi)容:要吃飯嘛?') # 返回值為True或者False print(result) # 添加按鈕 btn1 = tkinter.Button(root,text = 'ok',command = okqqq) btn1.pack() # 加入消息循環(huán) root.mainloop()
示例:askquestion
import tkinter # 導(dǎo)入消息對(duì)話框子模塊 import tkinter.messagebox # 創(chuàng)建主窗口 root = tkinter.Tk() # 設(shè)置窗口大小 root.minsize(300,300) # 聲明函數(shù) def question(): # 彈出對(duì)話框 result = tkinter.messagebox.askquestion(title = '標(biāo)題',message='內(nèi)容:你吃飯了嘛?') # 返回值為:yes/no print(result) # 添加按鈕 btn1 = tkinter.Button(root,text = 'question',command = question) btn1.pack() # 加入消息循環(huán) root.mainloop()
示例:askretrycancel (重試)
import tkinter # 導(dǎo)入消息對(duì)話框子模塊 import tkinter.messagebox # 創(chuàng)建主窗口 root = tkinter.Tk() # 設(shè)置窗口大小 root.minsize(300,300) # 聲明函數(shù) def retry(): # 彈出對(duì)話框 result = tkinter.messagebox.askretrycancel(title = '標(biāo)題',message='內(nèi)容:女生拒絕了你???') # 返回值為:True或者False print(result) # 添加按鈕 btn1 = tkinter.Button(root,text = 'retry',command = retry) btn1.pack() # 加入消息循環(huán) root.mainloop()
示例:askyesno
# 聲明函數(shù) def yesno(): # 彈出對(duì)話框 result = tkinter.messagebox.askyesno(title = '標(biāo)題',message='內(nèi)容:你喜歡我嗎?') # 返回值為:True或者False print(result) # 添加按鈕 btn1 = tkinter.Button(root,text = 'yesno',command = yesno) btn1.pack()
示例:showerror (出錯(cuò))
# 聲明函數(shù) def error(): # 彈出對(duì)話框 result = tkinter.messagebox.showerror(title = '出錯(cuò)了!',message='內(nèi)容:你的年齡不符合要求。') # 返回值為:ok print(result) # 添加按鈕 btn1 = tkinter.Button(root,text = 'error',command = error) btn1.pack()
示例:showwarning(警告)
# 聲明函數(shù) def warning(): # 彈出對(duì)話框 result = tkinter.messagebox.showwarning(title = '出錯(cuò)了!',message='內(nèi)容:十八歲以下禁止進(jìn)入。') # 返回值為:ok print(result) # 添加按鈕 btn1 = tkinter.Button(root,text = 'warning',command = warning) btn1.pack()
示例:showinto (信息提示)
# 聲明函數(shù) def info(): # 彈出對(duì)話框 result = tkinter.messagebox.showinfo(title = '信息提示!',message='內(nèi)容:您的女朋友收到一只不明來歷的口紅!') # 返回值為:ok print(result) # 添加按鈕 btn1 = tkinter.Button(root,text = 'info',command = info) btn1.pack()
2.simpledialog 簡(jiǎn)單信息對(duì)話框
示例:asksting(獲取字符串)
import tkinter # 導(dǎo)入子模塊 import tkinter.simpledialog # 創(chuàng)建主窗口 root = tkinter.Tk() # 設(shè)置窗口大小 root.minsize(300,300) # 創(chuàng)建函數(shù) def askname(): # 獲取字符串(標(biāo)題,提示,初始值) result = tkinter.simpledialog.askstring(title = '獲取信息',prompt='請(qǐng)輸入姓名:',initialvalue = '可以設(shè)置初始值') # 打印內(nèi)容 print(result) # 添加按鈕 btn = tkinter.Button(root,text = '獲取用戶名',command = askname) btn.pack() # 加入消息循環(huán) root.mainloop()
示例:askinteger(獲取整型)
import tkinter # 導(dǎo)入消息對(duì)話框子模塊 import tkinter.simpledialog # 創(chuàng)建主窗口 root = tkinter.Tk() # 設(shè)置窗口大小 root.minsize(300,300) # 創(chuàng)建函數(shù) def askage(): # 獲取整型(標(biāo)題,提示,初始值) result = tkinter.simpledialog.askinteger(title = '獲取信息',prompt='請(qǐng)輸入年齡:',initialvalue = '18') # 打印內(nèi)容 print(result) # 添加按鈕 btn = tkinter.Button(root,text = '獲取年齡',command = askage) btn.pack() # 加入消息循環(huán) root.mainloop()
示例:askfloat(獲取浮點(diǎn)型)
import tkinter # 導(dǎo)入消息對(duì)話框子模塊 import tkinter.simpledialog # 創(chuàng)建主窗口 root = tkinter.Tk() # 設(shè)置窗口大小 root.minsize(300,300) # 創(chuàng)建函數(shù) def askheight(): # 獲取浮點(diǎn)型數(shù)據(jù)(標(biāo)題,提示,初始值) result = tkinter.simpledialog.askfloat(title = '獲取信息',prompt='請(qǐng)輸入身高(單位:米):',initialvalue = '18.0') # 打印內(nèi)容 print(result) # 添加按鈕 btn = tkinter.Button(root,text = '獲取身高',command = askheight) btn.pack() # 加入消息循環(huán) root.mainloop()
以上就是python tkinter的消息框模塊的詳細(xì)內(nèi)容,更多關(guān)于python tkinter消息框的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- Python tkinter模塊彈出窗口及傳值回到主窗口操作詳解
- Python實(shí)現(xiàn)隨機(jī)選擇元素功能
- Python編程使用tkinter模塊實(shí)現(xiàn)計(jì)算器軟件完整代碼示例
- Python3 Tkinter選擇路徑功能的實(shí)現(xiàn)方法
- Python Tkinter模塊 GUI 可視化實(shí)例
- 詳解python tkinter模塊安裝過程
- python switch 實(shí)現(xiàn)多分支選擇功能
- python實(shí)現(xiàn)錄制全屏和選擇區(qū)域錄屏功能
- python tkinter模塊的簡(jiǎn)單使用
- python使用tkinter模塊實(shí)現(xiàn)文件選擇功能
相關(guān)文章
Python中正則表達(dá)式妙用之以搜索電子郵件地址為例
這篇文章主要給大家介紹了關(guān)于Python中正則表達(dá)式妙用之以搜索電子郵件地址為例的相關(guān)資料,正則表達(dá)式經(jīng)常被用到,而自己總是記不全,匯總一份完整的以備不時(shí)之需,需要的朋友可以參考下2024-05-05解決Django no such table: django_session的問題
這篇文章主要介紹了解決Django no such table: django_session的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-04-04TensorFlow2.4完成Word2vec詞嵌入訓(xùn)練方法詳解
這篇文章主要為大家介紹了TensorFlow2.4完成Word2vec詞嵌入訓(xùn)練方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11python實(shí)現(xiàn)圖像高斯金字塔的示例代碼
這篇文章主要介紹了python實(shí)現(xiàn)圖像高斯金字塔的示例代碼,幫助大家更好的利用python處理圖片,感興趣的朋友可以了解下2020-12-12Python實(shí)現(xiàn)按鍵精靈版的連點(diǎn)器
這篇文章主要為大家詳細(xì)介紹了如何利用Python實(shí)現(xiàn)按鍵精靈版的連點(diǎn)器,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以了解一下2023-06-06