效果依次为:
代码:
import tkinter as tk
import tkinter.messagebox
window = tk.Tk()
window.title('my window')
window.geometry('200x200')
def hit_me():
#tk.messagebox.showinfo(title='Hi',message='hahahahha')
#tk.messagebox.showerror(title='Hi',message='has error')
#tk.messagebox.showwarning(title='Hi', message='has warning')
#print(tk.messagebox.askokcancel(title='Hi',message='hahaha'))
#print(tk.messagebox.askquestion(title='Hi', message='hahaha'))
#print(tk.messagebox.askyesno(title='Hi', message='hahaha'))
# print(tk.messagebox.askretrycancel(title='Hi', message='hahaha'))
print(tk.messagebox.askyesnocancel(title='Hi', message='hahaha'))
tk.Button(window,text='hit me',command=hit_me).pack()
window.mainloop()
其中:
tk.messagebox.showinfo(title='',message='')#提示信息对话窗
tk.messagebox.showwarning()#提出警告对话窗
tk.messagebox.showerror()#提出错误对话窗
tk.messagebox.askquestion()#询问选择对话窗
print(tk.messagebox.askquestion())#返回yes和no
print(tk.messagebox.askokcancel())#返回true和false
print(tk.messagebox.askyesno())#返回true和false
print(tk.messagebox.askretrycancel())#返回true和false