### Install PyMsgBox Source: https://context7.com/asweigart/pymsgbox/llms.txt Install PyMsgBox using pip. ```bash pip install PyMsgBox ``` -------------------------------- ### Display a Prompt Box Source: https://github.com/asweigart/pymsgbox/blob/master/docs/basics.md Use `prompt` to get text input from the user with OK and Cancel buttons. Returns the entered text or None if Cancel is clicked. ```python >>> pymsgbox.prompt('What does the fox say?', default='This reference dates this example.') 'This reference dates this example.' ``` -------------------------------- ### Windows Native Confirm Example Source: https://github.com/asweigart/pymsgbox/blob/master/docs/native.md On Windows, the native `confirm()` function only provides 'OK' and 'Cancel' buttons. The return value corresponds to the first button text if 'OK' is clicked, and the second if 'Cancel' is clicked. ```python >>> pymsgbox.native.confirm('Nuke the site from orbit?', 'Confirm nuke', ["Yes, I'm sure.", 'Cancel']) "Yes, I'm sure." ``` -------------------------------- ### Windows Native Alert Example Source: https://github.com/asweigart/pymsgbox/blob/master/docs/native.md On Windows, the native `alert()` function displays an 'OK' button regardless of the `button` argument. The return value is always 'OK'. ```python >>> pymsgbox.native.alert('This is an alert.', 'Alert!') 'OK' ``` -------------------------------- ### Import and Use Native Alert Source: https://github.com/asweigart/pymsgbox/blob/master/docs/native.md To use native message boxes, import the `native` module and call its functions directly. This example shows how to display a native alert. ```python >>> import pymsgbox >>> pymsgbox.native.alert('This is an alert.', 'The title.') ``` -------------------------------- ### Basic PyMsgBox Functions Source: https://github.com/asweigart/pymsgbox/blob/master/docs/quickstart.md Demonstrates the basic usage of PyMsgBox functions for alerts, confirmations, prompts, and password input. Ensure Tkinter is installed on Linux Python 2. ```python >>> import pymsgbox >>> pymsgbox.alert('This is an alert.') ``` ```python >>> pymsgbox.confirm('Click OK to continue, click Cancel to cancel.') ``` ```python >>> pymsgbox.prompt('Enter your name.') ``` ```python >>> pymsgbox.password('Enter your password. (It will appear hidden in this text field.)') ``` -------------------------------- ### Display a Password Box Source: https://github.com/asweigart/pymsgbox/blob/master/docs/basics.md Use `password` to get sensitive text input, masking characters with '*'. Returns the entered text or None if Cancel is clicked. ```python >>> pymsgbox.password('Enter your password.') '12345' ``` -------------------------------- ### Localizing PyMsgBox Button Labels Source: https://context7.com/asweigart/pymsgbox/llms.txt Shows how to change the default button labels for all PyMsgBox dialogs by overriding module-level constants. This example switches the labels to French. ```python import pymsgbox # Switch to French pymsgbox.OK_TEXT = 'D\'accord' pymsgbox.CANCEL_TEXT = 'Annuler' pymsgbox.YES_TEXT = 'Oui' pymsgbox.NO_TEXT = 'Non' pymsgbox.RETRY_TEXT = 'Réessayer' pymsgbox.ABORT_TEXT = 'Abandonner' pymsgbox.IGNORE_TEXT = 'Ignorer' pymsgbox.TIMEOUT_RETURN_VALUE = 'Délai dépassé' result = pymsgbox.confirm('Voulez-vous continuer ?', 'Confirmation') # Buttons now read "D'accord" and "Annuler" print(result) ``` -------------------------------- ### Using Native Win32 Message Boxes (Windows Only) Source: https://context7.com/asweigart/pymsgbox/llms.txt Illustrates how to use the native Windows WinAPI `MessageBox` for `alert()` and `confirm()` functions. This provides a native look and feel and supports icon flags. Unsupported combinations fall back to tkinter. ```python # Option 1: use the native sub-module directly import pymsgbox pymsgbox.native.alert('Deployment finished.', 'CI/CD Pipeline', icon=pymsgbox.INFO) pymsgbox.native.confirm('Reboot the server now?', 'Maintenance', icon=pymsgbox.WARNING) ``` ```python # Option 2: shadow the top-level name for drop-in replacement import pymsgbox.native as pymsgbox result = pymsgbox.alert('Operation complete.', 'Done') print(result) # 'OK' result = pymsgbox.confirm( 'Nuke the site from orbit?', 'Confirm', buttons=["Yes, I'm sure.", 'Cancel'] ) print(result) # "Yes, I'm sure." or "Cancel" # Timeouts and custom button labels are not supported natively — # PyMsgBox falls back to tkinter automatically in those cases: result = pymsgbox.alert('Closing in 3 s', timeout=3000) print(result) # works via tkinter fallback ``` -------------------------------- ### Import PyMsgBox Functions Source: https://github.com/asweigart/pymsgbox/blob/master/README.md To use PyMsgBox, import all its functions using the asterisk wildcard. ```python >>> from pymsgbox import * ``` -------------------------------- ### Display an Alert Box Source: https://github.com/asweigart/pymsgbox/blob/master/docs/basics.md Use `alert` to show a simple message with an OK button. It returns the text of the button clicked. ```python >>> pymsgbox.alert('This is an alert.', 'Alert!') 'OK' ``` -------------------------------- ### prompt Source: https://github.com/asweigart/pymsgbox/blob/master/docs/basics.md Displays a message box with text input, and OK & Cancel buttons. It returns the text entered by the user, or None if Cancel was clicked. ```APIDOC ## prompt ### Description Displays a message box with text input, and OK & Cancel buttons. Returns the text entered, or None if Cancel was clicked. ### Method Signature `prompt(text='', title='', defaultValue='')` ### Parameters - **text** (string) - Optional - The message to display prompting for input. - **title** (string) - Optional - The title of the prompt window. - **defaultValue** (string) - Optional - The default text to pre-fill in the input field. ### Example ```pycon >>> import pymsgbox >>> pymsgbox.prompt('What does the fox say?', default='This reference dates this example.') 'This reference dates this example.' ``` ``` -------------------------------- ### Display a Confirmation Box Source: https://github.com/asweigart/pymsgbox/blob/master/docs/basics.md Use `confirm` to display a message with customizable buttons. It returns the text of the button clicked. ```python >>> pymsgbox.confirm('Nuke the site from orbit?', 'Confirm nuke', ["Yes, I'm sure.", 'Cancel']) "Yes, I'm sure." ``` -------------------------------- ### password(text='', title='', default='', mask='*', timeout=None) Source: https://context7.com/asweigart/pymsgbox/llms.txt Identical to prompt() but masks the typed characters (default mask is '*'). Returns the entered string, or None if Cancel was clicked. ```APIDOC ## password(text='', title='', default='', mask='*', timeout=None) ### Description Identical to `prompt()` but masks the typed characters (default mask is `'*'`). Returns the entered string, or `None` if Cancel was clicked. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **text** (string) - Optional - The message to display above the input field. - **title** (string) - Optional - The title of the password window. - **default** (string) - Optional - The default text to pre-fill in the input field. - **mask** (string) - Optional - The character used to mask the typed input. Defaults to '*'. - **timeout** (integer) - Optional - The time in milliseconds before the prompt auto-closes. If the timeout expires, the function returns 'Timeout'. ### Request Example ```python import pymsgbox # Standard password prompt secret = pymsgbox.password('Enter your API key:', 'Authentication') if secret is None: print('Authentication cancelled.') else: print(f'Key received (length {len(secret)}).') # Custom mask character pin = pymsgbox.password('Enter your 4-digit PIN:', 'PIN Entry', mask='•') print(pin) # The actual digits, not the mask characters # With a pre-filled default (useful for editing existing credentials) token = pymsgbox.password('Update token (leave blank to keep current):', default='') ``` ### Response #### Success Response (200) - **result** (string or None) - The string entered by the user, `None` if Cancel was clicked, or 'Timeout' if the timeout expired. ``` -------------------------------- ### prompt(text='', title='', default='', timeout=None) Source: https://context7.com/asweigart/pymsgbox/llms.txt Displays a modal dialog with a text input field and OK / Cancel buttons. Returns the string the user typed, or None if Cancel was clicked or the dialog was closed. ```APIDOC ## prompt(text='', title='', default='', timeout=None) ### Description Displays a modal dialog with a text input field and OK / Cancel buttons. Returns the string the user typed, or `None` if Cancel was clicked or the dialog was closed. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **text** (string) - Optional - The message to display above the input field. - **title** (string) - Optional - The title of the prompt window. - **default** (string) - Optional - The default text to pre-fill in the input field. Defaults to an empty string. - **timeout** (integer) - Optional - The time in milliseconds before the prompt auto-closes. If the timeout expires, the function returns 'Timeout'. ### Request Example ```python import pymsgbox # Basic text input name = pymsgbox.prompt('Enter your username:', 'Login') if name is None: print('User cancelled.') else: print(f'Hello, {name}!') # Pre-filled default value city = pymsgbox.prompt('Which city are you in?', 'Location', default='New York') print(city) # Returns typed text, or None on cancel # With timeout — returns 'Timeout' if not answered in time answer = pymsgbox.prompt('Quick! Name a colour:', 'Speed Round', timeout=4000) if answer == pymsgbox.TIMEOUT_RETURN_VALUE: print('Too slow!') elif answer is None: print('Cancelled.') else: print(f'You said: {answer}') ``` ### Response #### Success Response (200) - **result** (string or None) - The string typed by the user, `None` if Cancel was clicked or the dialog was closed, or 'Timeout' if the timeout expired. ``` -------------------------------- ### Localization Source: https://github.com/asweigart/pymsgbox/blob/master/docs/basics.md The default strings for buttons and timeouts can be customized by modifying specific variables within the pymsgbox module. ```APIDOC ## Localization ### Description You can change the default 'OK', 'Cancel', and 'Timeout' strings by changing `pymsgbox.OK_TEXT`, `pymsgbox.CANCEL_TEXT`, and `pymsgbox.TIMEOUT_TEXT` variables respectively. ### Example ```pycon >>> import pymsgbox >>> pymsgbox.OK_TEXT = 'Confirm' >>> pymsgbox.CANCEL_TEXT = 'Decline' >>> pymsgbox.TIMEOUT_TEXT = 'Timed Out' ``` ``` -------------------------------- ### alert Source: https://github.com/asweigart/pymsgbox/blob/master/docs/basics.md Displays a simple message box with text and a single OK button. It returns the text of the button clicked on. ```APIDOC ## alert ### Description Displays a simple message box with text and a single OK button. Returns the text of the button clicked on. ### Method Signature `alert(text='', title='', button='OK')` ### Parameters - **text** (string) - Optional - The message to display in the alert box. - **title** (string) - Optional - The title of the alert window. - **button** (string) - Optional - The text for the single button (defaults to 'OK'). ### Example ```pycon >>> import pymsgbox >>> pymsgbox.alert('This is an alert.', 'Alert!') 'OK' ``` ``` -------------------------------- ### Text Input Prompt Source: https://context7.com/asweigart/pymsgbox/llms.txt Opens a dialog with a text field for user input, returning the entered string or None on cancel. ```python import pymsgbox # Basic text input name = pymsgbox.prompt('Enter your username:', 'Login') if name is None: print('User cancelled.') else: print(f'Hello, {name}!') ``` ```python # Pre-filled default value city = pymsgbox.prompt('Which city are you in?', 'Location', default='New York') print(city) # Returns typed text, or None on cancel ``` ```python # With timeout — returns 'Timeout' if not answered in time answer = pymsgbox.prompt('Quick! Name a colour:', 'Speed Round', timeout=4000) if answer == pymsgbox.TIMEOUT_RETURN_VALUE: print('Too slow!') elif answer is None: print('Cancelled.') else: print(f'You said: {answer}') ``` -------------------------------- ### Using Native OS Message Boxes Source: https://github.com/asweigart/pymsgbox/blob/master/docs/quickstart.md Imports the native OS message box module for PyMsgBox. Note that not all message boxes have native support and will fall back to the default implementation. ```python >>> import pymsgbox.native as pymsgbox ``` -------------------------------- ### Display Prompt Message Box Source: https://github.com/asweigart/pymsgbox/blob/master/README.md Use the prompt function to display a message box with a text input field, along with OK and Cancel buttons. It returns the entered text or None if Cancel is clicked. ```python >>> prompt(text='', title='' , defaultValue='') ``` -------------------------------- ### Password Input Prompt Source: https://context7.com/asweigart/pymsgbox/llms.txt Similar to prompt(), but masks the input characters. Returns the entered string or None on cancel. ```python import pymsgbox # Standard password prompt secret = pymsgbox.password('Enter your API key:', 'Authentication') if secret is None: print('Authentication cancelled.') else: print(f'Key received (length {len(secret)}).') ``` ```python # Custom mask character pin = pymsgbox.password('Enter your 4-digit PIN:', 'PIN Entry', mask='•') print(pin) # The actual digits, not the mask characters ``` ```python # With a pre-filled default (useful for editing existing credentials) token = pymsgbox.password('Update token (leave blank to keep current):', default='') ``` -------------------------------- ### password Source: https://github.com/asweigart/pymsgbox/blob/master/docs/basics.md Displays a message box with text input, and OK & Cancel buttons. Typed characters appear as asterisks (*). It returns the text entered, or None if Cancel was clicked. ```APIDOC ## password ### Description Displays a message box with text input, and OK & Cancel buttons. Typed characters appear as \*. Returns the text entered, or None if Cancel was clicked. ### Method Signature `password(text='', title='', defaultValue='', mask='*')` ### Parameters - **text** (string) - Optional - The message to display prompting for a password. - **title** (string) - Optional - The title of the password window. - **defaultValue** (string) - Optional - The default text to pre-fill in the input field. - **mask** (string) - Optional - The character used to mask input (defaults to '*'). ### Example ```pycon >>> import pymsgbox >>> pymsgbox.password('Enter your password.') '12345' ``` ``` -------------------------------- ### Display Alert Message Box Source: https://github.com/asweigart/pymsgbox/blob/master/README.md Use the alert function to display a simple message box with text and a single OK button. It returns the text of the button clicked. ```python >>> alert(text='', title='', button='OK') ``` -------------------------------- ### Using Timeout in PyMsgBox Functions Source: https://context7.com/asweigart/pymsgbox/llms.txt Demonstrates how to use the `timeout` parameter with different PyMsgBox functions. If the timeout is reached, the function returns `pymsgbox.TIMEOUT_RETURN_VALUE`. ```python import pymsgbox WAIT_MS = 2000 # 2 seconds for func, kwargs in [ (pymsgbox.alert, {'text': 'Alert will close.', 'timeout': WAIT_MS}), (pymsgbox.confirm, {'text': 'Confirm will close.', 'timeout': WAIT_MS}), (pymsgbox.prompt, {'text': 'Prompt will close.', 'timeout': WAIT_MS}), (pymsgbox.password,{'text': 'Password will close.', 'timeout': WAIT_MS}), ]: result = func(**kwargs) if result == pymsgbox.TIMEOUT_RETURN_VALUE: print(f'{func.__name__} timed out.') else: print(f'{func.__name__} returned: {result!r}') ``` -------------------------------- ### confirm Source: https://github.com/asweigart/pymsgbox/blob/master/docs/basics.md Displays a message box with OK and Cancel buttons. The number and text of buttons can be customized. It returns the text of the button clicked on. ```APIDOC ## confirm ### Description Displays a message box with OK and Cancel buttons. Number and text of buttons can be customized. Returns the text of the button clicked on. ### Method Signature `confirm(text='', title='', buttons=['OK', 'Cancel'])` ### Parameters - **text** (string) - Optional - The message to display in the confirmation box. - **title** (string) - Optional - The title of the confirmation window. - **buttons** (list of strings) - Optional - A list of strings for the buttons to display (defaults to ['OK', 'Cancel']). ### Example ```pycon >>> import pymsgbox >>> pymsgbox.confirm('Nuke the site from orbit?', 'Confirm nuke', ["Yes, I'm sure.", 'Cancel']) "Yes, I'm sure." ``` ``` -------------------------------- ### PyMsgBox Function Default Arguments Source: https://github.com/asweigart/pymsgbox/blob/master/docs/quickstart.md Shows the default arguments for PyMsgBox alert, confirm, prompt, and password functions. These can be customized when calling the functions. ```python >>> pymsgbox.alert(text='', title='', button='OK') ``` ```python >>> pymsgbox.confirm(text='', title='', buttons=['OK', 'Cancel']) ``` ```python >>> pymsgbox.prompt(text='', title='' , defaultValue='') ``` ```python >>> pymsgbox.password(text='', title='', defaultValue='', mask='*') ``` -------------------------------- ### Display Confirmation Message Box Source: https://github.com/asweigart/pymsgbox/blob/master/README.md Use the confirm function to display a message box with customizable buttons, defaulting to OK and Cancel. It returns the text of the button clicked. ```python >>> confirm(text='', title='', buttons=['OK', 'Cancel']) ``` -------------------------------- ### Confirmation Dialog Source: https://context7.com/asweigart/pymsgbox/llms.txt Presents a message with two or more buttons for user confirmation. Returns the label of the clicked button or None if closed. ```python import pymsgbox # Standard OK / Cancel result = pymsgbox.confirm('Do you want to overwrite the existing file?', 'Overwrite?') if result == 'OK': print('User confirmed overwrite.') else: print('User cancelled.') ``` ```python # Custom button labels result = pymsgbox.confirm( 'Permanently delete all records?', 'Danger Zone', buttons=["Yes, delete everything", 'Cancel'] ) print(result) # "Yes, delete everything" or "Cancel" ``` ```python # Three-button dialog result = pymsgbox.confirm( 'Save changes before closing?', 'Unsaved Changes', buttons=['Save', "Don't Save", 'Cancel'] ) print(result) # 'Save', "Don't Save", or 'Cancel' ``` ```python # Auto-close after 5 seconds result = pymsgbox.confirm('Continue?', timeout=5000) print(result) # 'OK', 'Cancel', or 'Timeout' ``` -------------------------------- ### Basic Alert Box Source: https://context7.com/asweigart/pymsgbox/llms.txt Displays a simple alert message with a default 'OK' button. The function returns the label of the clicked button. ```python import pymsgbox # Basic alert result = pymsgbox.alert('Backup completed successfully.', 'Backup') print(result) # 'OK' ``` ```python # Custom button label result = pymsgbox.alert('Read the terms before continuing.', 'Notice', button='I Understand') print(result) # 'I Understand' ``` ```python # Auto-closing alert after 3 seconds result = pymsgbox.alert('This window will close automatically.', 'Auto-close', timeout=3000) print(result) # 'OK' if clicked, 'Timeout' if timer expired ``` -------------------------------- ### Confirmation Box with Timeout Source: https://github.com/asweigart/pymsgbox/blob/master/docs/basics.md The `confirm` function, like others, accepts a `timeout` parameter in milliseconds. If the timeout is reached, it returns 'Timeout'. ```python >>> pymsgbox.confirm('Nuke the site from orbit?', 'Confirm nuke', ["Yes, I'm sure.", 'Cancel'], timeout=2000) # closes after 2000 milliseconds (2 seconds) "Timeout" ``` -------------------------------- ### confirm(text='', title='', buttons=('OK', 'Cancel'), timeout=None) Source: https://context7.com/asweigart/pymsgbox/llms.txt Displays a modal message box with two or more customizable buttons. Returns the label of the button clicked, or None if the dialog is closed via the window's close button. ```APIDOC ## confirm(text='', title='', buttons=('OK', 'Cancel'), timeout=None) ### Description Displays a modal message box with two or more customizable buttons. Returns the label of the button clicked, or `None` if the dialog is closed via the window's close button. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **text** (string) - Optional - The message to display in the confirmation box. - **title** (string) - Optional - The title of the confirmation window. - **buttons** (tuple of strings) - Optional - A tuple of strings representing the labels for the buttons. Defaults to ('OK', 'Cancel'). - **timeout** (integer) - Optional - The time in milliseconds before the confirmation auto-closes. If the timeout expires, the function returns 'Timeout'. ### Request Example ```python import pymsgbox # Standard OK / Cancel result = pymsgbox.confirm('Do you want to overwrite the existing file?', 'Overwrite?') if result == 'OK': print('User confirmed overwrite.') else: print('User cancelled.') # Custom button labels result = pymsgbox.confirm( 'Permanently delete all records?', 'Danger Zone', buttons=["Yes, delete everything", 'Cancel'] ) print(result) # "Yes, delete everything" or "Cancel" # Three-button dialog result = pymsgbox.confirm( 'Save changes before closing?', 'Unsaved Changes', buttons=['Save', "Don't Save", 'Cancel'] ) print(result) # 'Save', "Don't Save", or 'Cancel' # Auto-close after 5 seconds result = pymsgbox.confirm('Continue?', timeout=5000) print(result) # 'OK', 'Cancel', or 'Timeout' ``` ### Response #### Success Response (200) - **result** (string or None) - The label of the button clicked, `None` if the dialog was closed, or 'Timeout' if the timeout expired. ``` -------------------------------- ### alert(text='', title='', button='OK', timeout=None) Source: https://context7.com/asweigart/pymsgbox/llms.txt Displays a modal message box with a single dismissal button. Returns the label of the button that was clicked. If a timeout (milliseconds) is given and expires before the user acts, returns 'Timeout'. ```APIDOC ## alert(text='', title='', button='OK', timeout=None) ### Description Displays a modal message box with a single dismissal button. Returns the label of the button that was clicked. If a `timeout` (milliseconds) is given and expires before the user acts, returns `'Timeout'`. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **text** (string) - Optional - The message to display in the alert box. - **title** (string) - Optional - The title of the alert window. - **button** (string) - Optional - The label for the dismissal button. Defaults to 'OK'. - **timeout** (integer) - Optional - The time in milliseconds before the alert auto-closes. If the timeout expires, the function returns 'Timeout'. ### Request Example ```python import pymsgbox # Basic alert result = pymsgbox.alert('Backup completed successfully.', 'Backup') print(result) # 'OK' # Custom button label result = pymsgbox.alert('Read the terms before continuing.', 'Notice', button='I Understand') print(result) # 'I Understand' # Auto-closing alert after 3 seconds result = pymsgbox.alert('This window will close automatically.', 'Auto-close', timeout=3000) print(result) # 'OK' if clicked, 'Timeout' if timer expired ``` ### Response #### Success Response (200) - **result** (string) - The label of the button clicked, or 'Timeout' if the timeout expired. ``` -------------------------------- ### Timeout Parameter Source: https://github.com/asweigart/pymsgbox/blob/master/docs/basics.md All four PyMsgBox functions (alert, confirm, prompt, password) support a `timeout` parameter. This parameter takes a number of milliseconds, after which the message box will automatically close and return the string 'Timeout'. ```APIDOC ## Timeout Parameter ### Description 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'`. ### Example ```pycon >>> import pymsgbox >>> pymsgbox.confirm('Nuke the site from orbit?', 'Confirm nuke', ["Yes, I'm sure.", 'Cancel'], timeout=2000) # closes after 2000 milliseconds (2 seconds) "Timeout" ``` ``` -------------------------------- ### Display Password Message Box Source: https://github.com/asweigart/pymsgbox/blob/master/README.md Use the password function for secure text input, masking characters with a specified mask (defaulting to '*'). It returns the entered text or None if Cancel is clicked. ```python >>> password(text='', title='', defaultValue='', mask='*') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.