PyMsgBox
PyMsgBox is a simple, cross-platform, pure Python module designed to display JavaScript-like message boxes. It provides `alert()`, `confirm()`, `prompt()`, and `password()` functions. Currently at version 2.0.1, the library leverages Python's built-in Tkinter module for its graphical user interface, offering a consistent experience across different operating systems. While it aims for a pure Python implementation, underlying OS GUI toolkit installations (like `python-tk` on Linux) may sometimes be required for Tkinter to function correctly. The project is actively maintained, with releases primarily driven by bug fixes and minor enhancements.
Warnings
- gotcha PyMsgBox relies on Python's built-in Tkinter module for its GUI. On some Linux distributions, Tkinter may require an additional system package (e.g., `python-tk` or `tk`) to be installed, even though Python itself is installed.
- gotcha The `pymsgbox.native` module provides limited support for displaying OS-native message boxes. However, these native dialogs may not support all arguments (e.g., custom buttons for `alert()` or `confirm()` on Windows) and will default back to Tkinter-based dialogs if certain features are unsupported on the platform.
- gotcha When using `prompt()` or `password()` functions, clicking the red 'X' (close) button on the dialog typically behaves the same as clicking the 'Cancel' button, returning `None`. The dialog will block program execution until closed by the user.
- gotcha There is a discrepancy between the latest PyPI release version (2.0.1) and the `__version__` string found in the `__init__.py` of the GitHub master branch (1.0.9). This may cause confusion for developers who check the source code directly for the latest version or expected features.
Install
-
pip install PyMsgBox
Imports
- alert
import pymsgbox pymsgbox.alert('Hello!') - confirm
import pymsgbox response = pymsgbox.confirm('Proceed?') - prompt
import pymsgbox name = pymsgbox.prompt('Your Name:') - password
import pymsgbox pw = pymsgbox.password('Password:')
Quickstart
import pymsgbox
# Display a simple alert box
pymsgbox.alert('This is an alert message!', 'My Application Alert')
# Display a confirmation box
response_confirm = pymsgbox.confirm('Do you want to continue?', 'Confirmation', ['Yes', 'No'])
print(f'Confirmation response: {response_confirm}')
# Display a prompt for text input
user_input = pymsgbox.prompt('Please enter your name:', 'Name Input', defaultValue='Guest')
print(f'User entered: {user_input}')
# Display a password input box
user_password = pymsgbox.password('Enter your secret password:', 'Secure Input', mask='*')
print(f'Password entered (masked): {user_password if user_password else "None"}')
# Example with timeout
timeout_response = pymsgbox.alert('This alert will close in 2 seconds.', timeout=2000)
print(f'Timeout alert response: {timeout_response}')