程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python learning notes - Tkinter_ MessageBox

編輯:Python

One 、 source

Check the source code , Run the source file , Show test cases .

Two 、 Case study

1.showinfo

from tkinter import *
from tkinter.messagebox import *
#1. create a window
root = Tk()
#2. Create and place components
b = Button(root,text=' Test pop up ')
b.pack()
#3. The binding event
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. create a window
root = Tk()
#2. Create and place components
b = Button(root,text=' Test pop up ')
b.pack()
#3. The binding event
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. create a window
root = Tk()
#2. Create and place components
b = Button(root,text=' Test pop up ')
b.pack()
#3. The binding event
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. create a window
root = Tk()
#2. Create and place components
b = Button(root,text=' Test pop up ')
b.pack()
#3. The binding event
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. create a window
root = Tk()
#2. Create and place components
b = Button(root,text=' Test pop up ')
b.pack()
#3. The binding event
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. create a window
root = Tk()
#2. Create and place components
b = Button(root,text=' Test pop up ')
b.pack()
#3. The binding event
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. create a window
root = Tk()
#2. Create and place components
b = Button(root,text=' Test pop up ')
b.pack()
#3. The binding event
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. create a window
root = Tk()
#2. Create and place components
b = Button(root,text=' Test pop up ')
b.pack()
#3. The binding event
def a(a):
print("try again", askretrycancel("Spam", "Try again?"))
b.bind('<Button-1>',a)
root.mainloop()

 

 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved