Web Analytics Made Easy - Statcounter
Skip to content

Popup

Popup - Display a popup Window with as many parms as you wish to include. This is the GUI equivalent of the "print" statement. It's also great for "pausing" your program's flow until the user can read some error messages.

If this popup doesn't have the features you want, then you can easily make your own. Popups can be accomplished in 1 line of code: choice, _ = sg.Window('Continue?', [[sg.T('Do you want to continue?')], [sg.Yes(s=10), sg.No(s=10)]], disable_close=True).read(close=True)

popup(
    args = *<1 or N objects>,
    title = None,
    button_color = None,
    background_color = None,
    text_color = None,
    button_type = 0,
    auto_close = False,
    auto_close_duration = None,
    custom_text = (None, None),
    non_blocking = False,
    icon = None,
    line_width = None,
    font = None,
    no_titlebar = False,
    grab_anywhere = False,
    keep_on_top = None,
    location = (None, None),
    relative_location = (None, None),
    any_key_closes = False,
    image = None,
    modal = True,
    button_justification = None,
    drop_whitespace = True
)

Parameter Descriptions

Name Type Default Description
*args Any Variable number of your arguments. Load up the call with stuff to see!
any_key_closes bool False If True then will turn on return_keyboard_events for the window which will cause window to close as soon as any key is pressed. Normally the return key only will close the window. Default is false.
auto_close bool False If True the window will automatically close
auto_close_duration int None time in seconds to keep window open before closing it automatically
background_color str None Window's background color
button_color (str, str) or str None Color of the buttons shown (text color, button color)
button_justification str None Speficies if buttons should be left, right or centered. Default is left justified
button_type int 0 NOT USER SET! Determines which pre-defined buttons will be shown (Default value = POPUP_BUTTONS_OK). There are many Popup functions and they call Popup, changing this parameter to get the desired effect.
custom_text (str, str) or str (None, None) A string or pair of strings that contain the text to display on the buttons
drop_whitespace bool True Controls is whitespace should be removed when wrapping text. Parameter is passed to textwrap.fill. Default is to drop whitespace (so popup remains backward compatible)
font str or Tuple[font_name, size, modifiers] None specifies the font family, size, etc. Tuple or Single string format 'name size styles'. Styles: italic * roman bold normal underline overstrike
grab_anywhere bool False If True can grab anywhere to move the window. If no_titlebar is True, grab_anywhere should likely be enabled too
icon str or bytes None icon to display on the window. Same format as a Window call
image str or bytes None Image to include at the top of the popup window
keep_on_top bool None If True the window will remain above all current windows
line_width int None Width of lines in characters. Defaults to MESSAGE_BOX_LINE_WIDTH
location (int, int) (None, None) Location on screen to display the top left corner of window. Defaults to window centered on screen
modal bool True If True then makes the popup will behave like a Modal window... all other windows are non-operational until this one is closed. Default = True
no_titlebar bool False If True will not show the frame around the window and the titlebar across the top
non_blocking bool False If True then will immediately return from the function without waiting for the user's input.
relative_location (int, int) (None, None) (x,y) location relative to the default location of the window, in pixels. Normally the window centers. This location is relative to the location the window would be created. Note they can be negative.
right_justify_buttons bool If True then the buttons will be "pushed" to the right side of the Window
text_color str None text color
title str None Optional title for the window. If none provided, the first arg will be used instead.
RETURN str or None Returns text of the button that was pressed. None will be returned if user closed window with X