In this tutorial we are going to learn about the messagebox in tkinter that is used in applications. We will learn about different functions which displays different kinds of popups. 

What is MessageBox in Tkinter?

The messagebox is used for showing messages inside the application. There are various functions that can be used for showing required messages depending on when to show them. The syntax for messagebox is:

Messagebox.functionname ( window_title, message, [features] )

Messagebox methods are as follows:

  • showinfo()
  • showwarning()
  • showerror ()
  • askquestion()
  • askokcancel()
  • askyesno ()
  • askretrycancel ()

Creating MessageBox

You can create simple a messagebox widget as follows:

from tkinter import *    
from tkinter import messagebox
screen = Tk()
def click_me():
   messagebox.askquestion("Your choice", "Do you want to close?")
click = Button(screen, text = "click me", command = click_me)

Output will be:

messagebox in tkinter

For more functionalities of tkinter message box, go here