Tkinter messagebox Example


Tkinter messagebox – Example

In Tkinter, the messagebox module provides a convenient way to display various types of message boxes or dialogs to interact with the user.

For example, you can show information, take an input string from user, ask for confirmation, etc.

The following is a screenshot of how a simple information messagebox appears.

In Windows OS

Tkinter messagebox in Windows OS
Tkinter messagebox in Windows OS

In MacOS

Tkinter messagebox in MacOS
Tkinter messagebox in MacOS

When you click on the OK button, the messagebox disappears.

messagebox Example Program

In this example, we display a simple messagebox with "Hello World! Welcome to PythonExamples.org" text.

We used messagebox.showinfo() method to display a greeting message as an information to the user.

Python Program

import tkinter as tk
from tkinter import messagebox

# Create the main window
window = tk.Tk()

# Show an information message box
messagebox.showinfo("Greeting", "Hello World! Welcome to PythonExamples.org")

# Run the application
window.mainloop()

Once the messagebox is displayed, you can click on the OK button. Then the messagebox disappears.

Output

In Windows 10

In MacOS

Tkinter messagebox – Example - MacOS
Tkinter messagebox screenshot from MacOS

Summary

In this Python Tkinter tutorial, we learned how to display a simple message in messagebox in Tkinter, with examples.