Here we are providing basic tutorial in Tkinter on how to create a message box in a Tkinter GUI application.

Sample code

The following Tkinter code will demonstrate the same:

from tkinter import *
import tkinter.messagebox

root = Tk()

tkinter.messagebox.showinfo("TKinter Messagebox", "Welcome to Tkinter Messagebox")

answer = tkinter.messagebox.askquestion("Question 1", "Are you a programmer?")

if answer == "yes":
    print("Welcome Programmer!")

root.mainloop()


In the above code, we imported a class messagebox from the standard tkinter library. Then a function of the same class is invoked in the code known as showinfo() which is used to create an alert box in the application. Secondly, a function of the same class is invoked in the code known as askquestion() which is used to ask a question in the application. If the answer is yes, some text is printed on the terminal window as shown below in the output.

Output

output


After clicking Yes on Question 1 of above window, the following output comes on the terminal :

output