Python‎ > ‎tkinter‎ > ‎

tkinter.messagebox


Definition
Create a message box in the widget.

Syntax
__init__(self, master=None, **options)
tkinter.messagebox()
messagebox()

FUNCTIONS
  • askokcancel(title=None, message=None, **options) " ---Ask if operation should proceed; return true if the answer is ok
  • askquestion(title=None, message=None, **options)--- Ask a question
  • askretrycancel(title=None, message=None, **options)--- Ask if operation should be retried; return true if the answer is yes
  • askyesno(title=None, message=None, **options)--- Ask a question; return true if the answer is yes
  • askyesnocancel(title=None, message=None, **options)--- Ask a question; return true if the answer is yes, None if cancelled.
  • showerror(title=None, message=None, **options)--- Show an error message
  • showinfo(title=None, message=None, **options)--- Show an info message
  • showwarning(title=None, message=None, **options)--- Show a warning message

Examples
The button command function is used to invoke the message box to display the random value.
from tkinter import*

master = Tk()
master.title("Random Widget")

def random_value():
    import random
    random1=random.random()
    messagebox.showinfo("Random Value is", random1)

labelframe=LabelFrame(master, fg="red", font=14, text="Random value generator")
labelframe.pack(side=BOTTOM)

button = Button(labelframe, text = "Click here", fg="blue", command = random_value)
button.pack(side=BOTTOM)

label = Label(labelframe, text = "Click on button to generate random value")
label.pack(side=BOTTOM)

master.mainloop()







Comments