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.

Advertisement

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.

Advertisement
Related:  Setting Python 2.7 in PyCharm

Vinish Kapoor

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