编程语言
首页 > 编程语言> > Python学习笔记—— tkinter_messagebox(消息框)

Python学习笔记—— tkinter_messagebox(消息框)

作者:互联网

一、来源

查源码,运行源码文件,展示测试案例。

二、案例

1.showinfo

from tkinter import *
from tkinter.messagebox import *

#1.创建窗口
root = Tk()
#2.创建组件摆放组件
b = Button(root,text='测试弹窗')
b.pack()
#3.绑定事件
def a(a):
    print("info", showinfo("Spam", "Egg Information"))

b.bind('<Button-1>',a)

root.mainloop()

 

2.warning

from tkinter import *
from tkinter.messagebox import *

#1.创建窗口
root = Tk()
#2.创建组件摆放组件
b = Button(root,text='测试弹窗')
b.pack()
#3.绑定事件
def a(a):
    print("warning", showwarning("Spam", "Egg Warning"))

b.bind('<Button-1>',a)

root.mainloop()

 

 3.error

from tkinter import *
from tkinter.messagebox import *

#1.创建窗口
root = Tk()
#2.创建组件摆放组件
b = Button(root,text='测试弹窗')
b.pack()
#3.绑定事件
def a(a):
    print("error", showerror("Spam", "Egg Alert"))

b.bind('<Button-1>',a)

root.mainloop()

 4.question

from tkinter import *
from tkinter.messagebox import *

#1.创建窗口
root = Tk()
#2.创建组件摆放组件
b = Button(root,text='测试弹窗')
b.pack()
#3.绑定事件
def a(a):
    print("question", askquestion("Spam", "Question?"))


b.bind('<Button-1>',a)

root.mainloop()

 

 5.proceed

from tkinter import *
from tkinter.messagebox import *

#1.创建窗口
root = Tk()
#2.创建组件摆放组件
b = Button(root,text='测试弹窗')
b.pack()
#3.绑定事件
def a(a):
    print("proceed", askokcancel("Spam", "Proceed?"))


b.bind('<Button-1>',a)

root.mainloop()

 

 

 6.yes/no

 

from tkinter import *
from tkinter.messagebox import *

#1.创建窗口
root = Tk()
#2.创建组件摆放组件
b = Button(root,text='测试弹窗')
b.pack()
#3.绑定事件
def a(a):
    print("yes/no", askyesno("Spam", "Got it?"))


b.bind('<Button-1>',a)

root.mainloop()

 7.yes/no/cancel

from tkinter import *
from tkinter.messagebox import *

#1.创建窗口
root = Tk()
#2.创建组件摆放组件
b = Button(root,text='测试弹窗')
b.pack()
#3.绑定事件
def a(a):
    print("yes/no/cancel", askyesnocancel("Spam", "Want it?"))


b.bind('<Button-1>',a)

root.mainloop()

 

 8.try again

from tkinter import *
from tkinter.messagebox import *

#1.创建窗口
root = Tk()
#2.创建组件摆放组件
b = Button(root,text='测试弹窗')
b.pack()
#3.绑定事件
def a(a):
    print("try again", askretrycancel("Spam", "Try again?"))


b.bind('<Button-1>',a)

root.mainloop()

 

 

标签:messagebox,tkinter,Python,创建,组件,import,root
来源: https://blog.csdn.net/tscaxx/article/details/123035654