You are currently viewing 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__':
    alert('Hello', 'Hello World')
    alert('Hello Again', 'Hello World 2', kind='warning')


Ceate alert message using Tkinter.

Related:  Setting Python 2.7 in PyCharm

Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of and a question and answer forum for developers.