Python Message Box Without huge library dependency Python Message Box Without huge library dependency windows windows

Python Message Box Without huge library dependency


You can use the ctypes library, which comes installed with Python:

import ctypesMessageBox = ctypes.windll.user32.MessageBoxWMessageBox(None, 'Hello', 'Window title', 0)

Above code is for Python 3.x. For Python 2.x, use MessageBoxA instead of MessageBoxW as Python 2 uses non-unicode strings by default.


There are also a couple prototyped in the default libraries without using ctypes.

Simple message box:

import win32uiwin32ui.MessageBox("Message", "Title")

Other Options

if win32ui.MessageBox("Message", "Title", win32con.MB_YESNOCANCEL) == win32con.IDYES:    win32ui.MessageBox("You pressed 'Yes'")

There's also a roughly equivalent one in win32gui and another in win32api. Docs for all appear to be in C:\Python{nn}\Lib\site-packages\PyWin32.chm


The PyMsgBox module uses Python's tkinter, so it doesn't depend on any other third-party modules. You can install it with pip install pymsgbox.

The function names are similar to JavaScript's alert(), confirm(), and prompt() functions:

>>> import pymsgbox>>> pymsgbox.alert('This is an alert!')>>> user_response = pymsgbox.prompt('What is your favorite color?')