popup - Output Popups (Popup Windows 1 of 4)
This line of code and the details about this one function, this call to popup
, says a lot about PySimpleGUI including:
- The terrible, often unsuccessful, attempts at humor in the documentation, code, examples.
- It appears simple, but has a the capability to be much more sophisticated should you care to use additional features of this function.
- You see 1 parameter used, but there are an 19 additional, optional parameters.
- There are numerous "flavors" of this one call with settings pre-determined for some of the more common operations.
- Want a popup without a titlebar? You can do that with a parameter or call
popup_no_titlebar()
- Want a popup without a titlebar? You can do that with a parameter or call
- It is documented in the call reference. It has docstrings to enable PyCharm and other IDEs to type-check your parameters and return values
- There are Demo Programs written specifically to teach you how to use it.
- It's a "real window". No tricks & no cheating. This is every bit as real and valid as all other tkinter windows.
- The colors are automatically set to match your "theme"
- The icon matches your project's icon
- It's portable across the other "ports" of PySimpleGUI (more on this much later)
Meet Your "popup
Pals"
popup
popup_animated
popup_annoying
popup_auto_close
popup_cancel
popup_error
popup_error_with_traceback
popup_get_date
popup_get_file
popup_get_folder
popup_get_text
popup_menu
popup_no_border
popup_no_buttons
popup_no_frame
popup_no_titlebar
popup_no_wait
popup_non_blocking
popup_notify
popup_ok
popup_ok_cancel
popup_quick
popup_quick_message
popup_scrolled
popup_timed
popup_yes_no
With popups, you have 2 ways to get the desired result:
- Set the individual parameters to the basic
popup
function - Use a function that sets groups of parameters for you
For example, if you want to show a popup window without a titlebar, you could use either of these calls:
sg.popup('I do not have a titlebar.', no_titlebar=True)
sg.popup_no_titlebar('I do not have a titlebar.')
3 Results in 1 Call
When you call popup
there are 3 results
- The information you provide is displayed in the window
- The execution of your program is temporarily stopped at the popup until it's closed (assuming it's not a special non-blocking popup)
- You are given the button the user clicks
import PySimpleGUI as sg
# Lots of code before this point
# Check to see if the user wanted to exit....
if sg.popup_yes_no('Do you want to exit?') == 'Yes':
exit()
print('Continuing on...')
You can use popups to get a simple piece of information from your user. In this case, it's a Yes or No answer to a question. The button the user clicks to close the popup is the return value. If the window is closed with the "X", then sg.WIN_CLOSED
or sg.WINDOW_CLOSED
(which have the value of None
) is returned.
While these popup windows are described as "output type", as you can see, there is an input that's also possible to get using them.
Try It For Yourself
Experiment with the values returned.