Tkinter之messageBox

 
messagebox (python2中为tkMessageBox ):消息框,就是我们平时看到的弹窗。 需要定义一个触发功能,来触发这个弹窗,这里就用上前面学过的Button按钮,通过command调用功能,弹出各种类型的提示对话框。
 
示例:
import Tkinter as tk 
from tkMessageBox import * 
# 此处是python2.7的用法,python3.x要改为:from tkinter.messagebox import *,注意大小写
window = tk.Tk()
window.title('My Window')
window.geometry('500x300')  
 
def hit_me():
    showinfo(title='Hi', message='正常文本')            # 提示信息对话窗
    showwarning(title='Hi', message='有警告!')      # 提出警告对话窗
    showerror(title='Hi', message='出错了!')          # 提出错误对话窗
    askquestion(title='Hi', message='你好!')          # 询问选择对话窗return 'yes', 'no'
    askyesno(title='Hi', message='你好!')              # return 'True', 'False'
    askokcancel(title='Hi', message='你好!')         # return 'True', 'False'
 
l=tk.Button(window, text='hit me', bg='green', font=('Arial', 14), command=hit_me)
l.pack()
 
window.mainloop()
 
 
posted @ 2019-10-30 13:53  数之美  阅读(1592)  评论(0编辑  收藏  举报