From c28c5ef2d102dd635bc18083aecd7ad1348a4b65 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Sun, 30 Sep 2018 14:48:31 -0400 Subject: [PATCH] New Popup demo --- Demo_Popup_Custom.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Demo_Popup_Custom.py diff --git a/Demo_Popup_Custom.py b/Demo_Popup_Custom.py new file mode 100644 index 00000000..eb807938 --- /dev/null +++ b/Demo_Popup_Custom.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +import sys +if sys.version_info[0] >= 3: + import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg + +''' + Use this code as a starting point for creating your own Popup functions. + Rather than creating a long list of Popup high-level API calls, PySimpleGUI provides + you with the tools to easily create your own. If you need more than what the standard PopupGetText and + other calls provide, then it's time for you to graduate into making your own windows. Or, maybe you need + another window that pops-up over your primary window. Whatever the need, don't hesitate to dive in + and create your own Popup call. + + This example is for a DropDown / Combobox Popup. You provide it with a title, a message and the list + of values to choose from. It mimics the return values of existing Popup calls (None if nothing was input) +''' + + +def PopupDropDown(title, text, values): + window = sg.Window(title).Layout([[sg.Text(text)], + [sg.DropDown(values, key='_drop')], + [sg.OK(), sg.Cancel()]]) + button, values = window.Read() + return None if button != 'OK' else values['_drop'] + + +# ----------------------- Calling your PopupDropDown function ----------------------- + +values = ['choice {}'.format(x) for x in range(30)] + +print(PopupDropDown('My Title', 'Please make a selection', values))