Pymsgbox Lib
Pymsgbox Lib
Release 0.9.0
Al Sweigart
1 Quickstart 3
2 PyMsgBox Basics 5
2.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Timeout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4 Localization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
i
ii
PyMsgBox Documentation, Release 0.9.0
Contents:
Contents 1
PyMsgBox Documentation, Release 0.9.0
2 Contents
CHAPTER 1
Quickstart
On Linux Python 2, you need to first install Tkinter by running: sudo apt-get install python-tk
All of the arguments to PyMsgBox functions are optional.
(Only a few of the message boxes have native support. Unsupported message boxes will default to the normal message
boxes.)
3
PyMsgBox Documentation, Release 0.9.0
4 Chapter 1. Quickstart
CHAPTER 2
PyMsgBox Basics
2.1 Installation
2.2 Usage
There are four functions in PyMsgBox, which follow JavaScript’s message box naming conventions:
• alert(text='', title='', button='OK')
Displays a simple message box with text and a single OK button. Returns the text of the button
clicked on.
5
PyMsgBox Documentation, Release 0.9.0
2.3 Timeout
All four functions have a timeout parameter which takes a number of milliseconds. At the end of the timeout, the
message box will close and have a return value of 'Timeout'.
>>> pymsgbox.confirm('Nuke the site from orbit?', 'Confirm nuke', ["Yes, I'm sure.",
˓→'Cancel'], timeout=2000) # closes after 2000 milliseconds (2 seconds)
"Timeout"
2.3. Timeout 7
PyMsgBox Documentation, Release 0.9.0
2.4 Localization
You can change the default 'OK', 'Cancel‘, and 'Timeout' strings by changing pymsgbox.OK_TEXT,
pymsgbox.CANCEL_TEXT, and pymsgbox.TIMEOUT_TEXT variables respectively.
In addition to displaying message boxes using Python’s built-in TkInter GUI toolkit, PyMsgBox also has limited
support for displaying message boxes by calling the operating system’s native functions. These exist in the native
module. To use them, call:
3.1 Support
These are the platforms and functions that have native message box support. Functions that do are not supported will
default back to the normal TkInter-based message box.
Support as of v1.0.1:
Windows OS X Linux JVM / Jython
alert() Yes No No No
confirm() Yes No No No
prompt() No No No No
password() No No No No
The message box will only show a button with text “OK”, no matter what is passed for the button argument. The
button argument will be the text that is returned by the function, just like the TkInter alert().
9
PyMsgBox Documentation, Release 0.9.0
There will only be buttons “OK” and “Cancel”, no matter what is passed for the buttons argument. If “OK” is
clicked, the first item in the buttons list is returned (by default, this is 'OK'). If “Cancel” is clicked, the second
item in the buttons list is returned (by default, this is 'Cancel'), just like the TkInter confirm().
>>> pymsgbox.native.confirm('Nuke the site from orbit?', 'Confirm nuke', ["Yes, I'm
˓→sure.", 'Cancel'])
• genindex
• modindex
• search
11