Press "Enter" to skip to content

Alert Message Box in Python Using Tkinter

The below is an example of showing an alert message box in Python using the Tkinter library.

Showing Alert Message Box in Python Using Tkinter

In the following Python program, it will create two alert boxes, one to show a standard message and another one is to show a warning message using the Tkinter library.

from tkinter import messagebox, Tk


def alert(title, message, kind='info', hidemain=True):
    if kind not in ('error', 'warning', 'info'):
        raise ValueError('Unsupported alert kind.')

    show_method = getattr(messagebox, 'show{}'.format(kind))
    show_method(title, message)


if __name__ == '__main__':
    Tk().withdraw()
    alert('Hello', 'Hello World')
    alert('Hello Again', 'Hello World 2', kind='warning')

Output

Ceate alert message using Tkinter.