|
| 1 | +#!/usr/bin/env python |
| 2 | +import sys |
| 3 | +if sys.version_info[0] >= 3: |
| 4 | + import PySimpleGUI as sg |
| 5 | +else: |
| 6 | + import PySimpleGUI27 as sg |
| 7 | + |
| 8 | +''' |
| 9 | + Use this code as a starting point for creating your own Popup functions. |
| 10 | + Rather than creating a long list of Popup high-level API calls, PySimpleGUI provides |
| 11 | + you with the tools to easily create your own. If you need more than what the standard PopupGetText and |
| 12 | + other calls provide, then it's time for you to graduate into making your own windows. Or, maybe you need |
| 13 | + another window that pops-up over your primary window. Whatever the need, don't hesitate to dive in |
| 14 | + and create your own Popup call. |
| 15 | + |
| 16 | + This example is for a DropDown / Combobox Popup. You provide it with a title, a message and the list |
| 17 | + of values to choose from. It mimics the return values of existing Popup calls (None if nothing was input) |
| 18 | +''' |
| 19 | + |
| 20 | + |
| 21 | +def PopupDropDown(title, text, values): |
| 22 | + window = sg.Window(title).Layout([[sg.Text(text)], |
| 23 | + [sg.DropDown(values, key='_drop')], |
| 24 | + [sg.OK(), sg.Cancel()]]) |
| 25 | + button, values = window.Read() |
| 26 | + return None if button != 'OK' else values['_drop'] |
| 27 | + |
| 28 | + |
| 29 | +# ----------------------- Calling your PopupDropDown function ----------------------- |
| 30 | + |
| 31 | +values = ['choice {}'.format(x) for x in range(30)] |
| 32 | + |
| 33 | +print(PopupDropDown('My Title', 'Please make a selection', values)) |
0 commit comments