Python PySimpleGUI.Combo() Examples

The following are 16 code examples of PySimpleGUI.Combo(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PySimpleGUI , or try the search function .
Example #1
Source File: config_passive_repair.py    From kcauto with GNU General Public License v3.0 9 votes vote down vote up
def get_layout(cls):
        return sg.Column(
            [
                [
                    sg.Text('Passive Repair', **cls.LABEL_SETTINGS),
                    sg.Checkbox(
                        'Enabled',
                        key='passive_repair.enabled',
                        enable_events=True)
                ],
                [
                    sg.Text('Repair Threshold', **cls.LABEL_SETTINGS),
                    sg.Combo(
                        [
                            x.display_name for x in DamageStateEnum
                            if x in cls.VALID_DAMAGE_STATES],
                        default_value=DamageStateEnum.SCRATCH.display_name,
                        key='passive_repair.repair_threshold',
                        font=cls.FONT_10,
                        size=(13, 1))
                ],
                [
                    sg.Text('Slots to Reserve', **cls.LABEL_SETTINGS),
                    sg.Spin(
                        [x for x in range(
                            cls.MIN_SLOTS_RESERVED,
                            cls.MAX_SLOTS_RESERVED + 1)],
                        0,
                        key='passive_repair.slots_to_reserve',
                        font=cls.FONT_10,
                        size=(5, 1))
                ]
            ],
            key='config_passive_repair_col',
            visible=False) 
Example #2
Source File: Demo_Multiline_cprint_Printing.py    From PySimpleGUI with GNU Lesser General Public License v3.0 7 votes vote down vote up
def main():

    MLINE_KEY = '-ML-'+sg.WRITE_ONLY_KEY        # multiline element's key. Indicate it's an output only element
    MLINE_KEY2 = '-ML2-'+sg.WRITE_ONLY_KEY        # multiline element's key. Indicate it's an output only element
    MLINE_KEY3 = '-ML3-'+sg.WRITE_ONLY_KEY        # multiline element's key. Indicate it's an output only element

    output_key = MLINE_KEY


    layout = [  [sg.Text('Multiline Color Print Demo', font='Any 18')],
                [sg.Multiline('Multiline\n', size=(80,20), key=MLINE_KEY)],
                [sg.Multiline('Multiline2\n', size=(80,20), key=MLINE_KEY2)],
                [sg.Text('Text color:'), sg.Combo(list(color_map.keys()), size=(12,20), key='-TEXT COLOR-'),
                 sg.Text('on Background color:'), sg.Combo(list(color_map.keys()), size=(12,20), key='-BG COLOR-')],
                [sg.Input('Type text to output here', size=(80,1), key='-IN-')],
                [sg.Button('Print', bind_return_key=True), sg.Button('Print short'),
                 sg.Button('Force 1'), sg.Button('Force 2'),
                 sg.Button('Use Input for colors'), sg.Button('Toggle Output Location'), sg.Button('Exit')]  ]

    window = sg.Window('Window Title', layout)

    sg.cprint_set_output_destination(window, output_key)

    while True:             # Event Loop
        event, values = window.read()
        if event == sg.WIN_CLOSED or event == 'Exit':
            break
        if event == 'Print':
            sg.cprint(values['-IN-'], text_color=values['-TEXT COLOR-'], background_color=values['-BG COLOR-'])
        elif event == 'Print short':
            sg.cprint(values['-IN-'], c=(values['-TEXT COLOR-'], values['-BG COLOR-']))
        elif event.startswith('Use Input'):
            sg.cprint(values['-IN-'], colors=values['-IN-'])
        elif event.startswith('Toggle'):
            output_key = MLINE_KEY if output_key == MLINE_KEY2 else MLINE_KEY2
            sg.cprint_set_output_destination(window, output_key)
            sg.cprint('Switched to this output element', c='white on red')
        elif event == 'Force 1':
            sg.cprint(values['-IN-'], c=(values['-TEXT COLOR-'], values['-BG COLOR-']), key=MLINE_KEY)
        elif event == 'Force 2':
            sg.cprint(values['-IN-'], c=(values['-TEXT COLOR-'], values['-BG COLOR-']), key=MLINE_KEY2)

    window.close() 
Example #3
Source File: config_combat.py    From kcauto with GNU General Public License v3.0 7 votes vote down vote up
def lbas_group_node_line_generator(cls, group_id):
        return [
            sg.Text(f'LBAS Group {group_id}', **cls.LABEL_SETTINGS),
            sg.Checkbox(
                'Enabled',
                key=f'combat.lbas_group_{group_id}.enabled',
                font=cls.FONT_10,
                enable_events=True),
            sg.Combo(
                [''] + [x.display_name for x in NamedNodeEnum],
                key=f'combat.lbas_group_{group_id}_node_1',
                font=cls.FONT_10,
                size=(4, 1)),
            sg.Combo(
                [''] + [x.display_name for x in NamedNodeEnum],
                key=f'combat.lbas_group_{group_id}_node_2',
                font=cls.FONT_10,
                size=(4, 1)),
            cls.generate_clear_btn(
                f'combat.lbas_group_{group_id}_nodes')] 
Example #4
Source File: Demo_Settings_Save_Load.py    From PySimpleGUI with GNU Lesser General Public License v3.0 6 votes vote down vote up
def create_settings_window(settings):
    sg.theme(settings['theme'])

    def TextLabel(text): return sg.Text(text+':', justification='r', size=(15,1))

    layout = [  [sg.Text('Settings', font='Any 15')],
                [TextLabel('Max Users'), sg.Input(key='-MAX USERS-')],
                [TextLabel('User Folder'),sg.Input(key='-USER FOLDER-'), sg.FolderBrowse(target='-USER FOLDER-')],
                [TextLabel('Zipcode'),sg.Input(key='-ZIPCODE-')],
                [TextLabel('Theme'),sg.Combo(sg.theme_list(), size=(20, 20), key='-THEME-')],
                [sg.Button('Save'), sg.Button('Exit')]  ]

    window = sg.Window('Settings', layout, keep_on_top=True, finalize=True)

    for key in SETTINGS_KEYS_TO_ELEMENT_KEYS:   # update window with the values read from settings file
        try:
            window[SETTINGS_KEYS_TO_ELEMENT_KEYS[key]].update(value=settings[key])
        except Exception as e:
            print(f'Problem updating PySimpleGUI window from settings. Key = {key}')

    return window

########################################## Main Program Window & Event Loop ########################################## 
Example #5
Source File: config_combat_fleet_preset_popup.py    From kcauto with GNU General Public License v3.0 6 votes vote down vote up
def get_layout(cls, presets):
        return [
            [
                sg.Text('Combat Fleet Presets', font=cls.FONT_10),
            ],
            [
                sg.Listbox(
                    key='presets',
                    values=presets,
                    font=cls.FONT_10,
                    size=(19, 6),
                    enable_events=True),
            ],
            [
                cls.generate_remove_btn('presets', 'remove preset'),
                cls.generate_clear_btn('presets', 'clear presets'),
            ],
            [
                sg.Combo(
                    [str(x) for x in range(1, 15) if str(x) not in presets],
                    key='preset_combo',
                    font=cls.FONT_10,
                    size=(13, 1)),
                cls.generate_add_btn('presets', 'add', size=(5, 1)),
            ],
            [
                sg.Button('Save and Close', key='save'),
                sg.Button('Cancel', key='cancel'),
            ]
        ] 
Example #6
Source File: config_expedition_popup.py    From kcauto with GNU General Public License v3.0 6 votes vote down vote up
def get_layout(cls, fleet_id, expeditions, other_expeditions):
        return [
            [
                sg.Text(
                    f'Fleet {fleet_id} Expeditions',
                    font=cls.FONT_10),
            ],
            [
                sg.Listbox(
                    key='expeditions',
                    values=expeditions,
                    font=cls.FONT_10,
                    size=(34, 5),
                    enable_events=True)
            ],
            [
                cls.generate_remove_btn(
                    'expeditions', 'remove selected expedition', size=(20, 1)),
                cls.generate_clear_btn(
                    'expeditions', 'clear expeditions', size=(20, 1)),
            ],
            [
                sg.Combo(
                    [
                        x.display_name for x in ExpeditionEnum
                        if x.display_name
                        not in expeditions + other_expeditions],
                    key='expedition_combo',
                    font=cls.FONT_10,
                    size=(28, 1)),
                cls.generate_add_btn('expeditions', 'add', size=(5, 1)),
            ],
            [
                sg.Button('Save and Close', key='save'),
                sg.Button('Cancel', key='cancel'),
            ]
        ] 
Example #7
Source File: config_general.py    From kcauto with GNU General Public License v3.0 6 votes vote down vote up
def get_layout(cls):
        return sg.Column(
            [
                [
                    sg.Text('JST Offset', **cls.LABEL_SETTINGS),
                    sg.Spin(
                        [x for x in range(MIN_JST_OFFSET, MAX_JST_OFFSET + 1)],
                        0,
                        key='general.jst_offset',
                        font=cls.FONT_10,
                        size=(3, 1),
                        enable_events=True)
                ],
                [
                    sg.Text('Interaction Mode', **cls.LABEL_SETTINGS),
                    sg.Combo(
                        [x.display_name for x in InteractionModeEnum],
                        key='general.interaction_mode',
                        font=cls.FONT_10,
                        size=(13, 1))
                ],
                [
                    sg.Text('Chrome Dev Port', **cls.LABEL_SETTINGS),
                    sg.Spin(
                        [x for x in range(MIN_PORT, MAX_PORT + 1)],
                        DEFAULT_CHROME_DEV_PORT,
                        key='general.chrome_dev_port',
                        font=cls.FONT_10,
                        size=(5, 1),
                        enable_events=True)
                ]
            ],
            key='config_general_col',
            visible=True) 
Example #8
Source File: config_combat_node_formation_popup.py    From kcauto with GNU General Public License v3.0 6 votes vote down vote up
def get_layout(cls, node_formations):
        return [
            [
                sg.Text('Node Formations', font=cls.FONT_10),
            ],
            [
                sg.Listbox(
                    key='node_formations',
                    values=node_formations,
                    font=cls.FONT_10,
                    size=(32, 6),
                    enable_events=True),
            ],
            [
                cls.generate_remove_btn(
                    'node_formations', 'remove node formation'),
                cls.generate_clear_btn(
                    'node_formations', 'clear node formations'),
            ],
            [
                sg.Combo(
                    [
                        x.display_name for x in NodeEnum
                        if x.display_name
                        not in [y.split(':')[0] for y in node_formations]],
                    key='node_combo',
                    font=cls.FONT_10,
                    size=(4, 1)),
                sg.Text(' to ', font=cls.FONT_10),
                sg.Combo(
                    [x.display_name for x in FormationEnum],
                    key='formation_combo',
                    font=cls.FONT_10,
                    size=(15, 1)),
                cls.generate_add_btn('node_formations', 'add', size=(5, 1)),
            ],
            [
                sg.Button('Save and Close', key='save'),
                sg.Button('Cancel', key='cancel'),
            ]
        ] 
Example #9
Source File: config_combat_push_node_popup.py    From kcauto with GNU General Public License v3.0 6 votes vote down vote up
def get_layout(cls, nodes):
        return [
            [
                sg.Text('Push Nodes', font=cls.FONT_10),
            ],
            [
                sg.Listbox(
                    key='nodes',
                    values=nodes,
                    font=cls.FONT_10,
                    size=(19, 6),
                    enable_events=True),
            ],
            [
                cls.generate_remove_btn('nodes', 'remove node'),
                cls.generate_clear_btn('nodes', 'clear nodes'),
            ],
            [
                sg.Combo(
                    [
                        x.display_name for x in NamedNodeEnum
                        if x.display_name not in nodes],
                    key='node_combo',
                    font=cls.FONT_10,
                    size=(13, 1)),
                cls.generate_add_btn('nodes', 'add', size=(5, 1)),
            ],
            [
                sg.Button('Save and Close', key='save'),
                sg.Button('Cancel', key='cancel'),
            ]
        ] 
Example #10
Source File: config_combat_retreat_node_popup.py    From kcauto with GNU General Public License v3.0 6 votes vote down vote up
def get_layout(cls, nodes):
        return [
            [
                sg.Text('Retreat Nodes', font=cls.FONT_10),
            ],
            [
                sg.Listbox(
                    key='nodes',
                    values=nodes,
                    font=cls.FONT_10,
                    size=(19, 6),
                    enable_events=True),
            ],
            [
                cls.generate_remove_btn('nodes', 'remove node'),
                cls.generate_clear_btn('nodes', 'clear nodes'),
            ],
            [
                sg.Combo(
                    [
                        x.display_name for x in NodeEnum
                        if x.display_name not in nodes],
                    key='node_combo',
                    font=cls.FONT_10,
                    size=(13, 1)),
                cls.generate_add_btn('nodes', 'add', size=(5, 1)),
            ],
            [
                sg.Button('Save and Close', key='save'),
                sg.Button('Cancel', key='cancel'),
            ]
        ] 
Example #11
Source File: config_combat_node_nb_popup.py    From kcauto with GNU General Public License v3.0 6 votes vote down vote up
def get_layout(cls, node_nb):
        return [
            [
                sg.Text('Node Night Battles', font=cls.FONT_10),
            ],
            [
                sg.Listbox(
                    key='node_nb',
                    values=node_nb,
                    font=cls.FONT_10,
                    size=(28, 6),
                    enable_events=True),
            ],
            [
                cls.generate_remove_btn('node_nb', 'remove node night battle'),
                cls.generate_clear_btn('node_nb', 'clear node night battles'),
            ],
            [
                sg.Combo(
                    [
                        x.display_name for x in NamedNodeEnum
                        if x.display_name
                        not in [y.split(':')[0] for y in node_nb]],
                    key='node_combo',
                    font=cls.FONT_10,
                    size=(4, 1)),
                sg.Text(' to ', font=cls.FONT_10),
                sg.Combo(
                    [True, False],
                    key='nb_combo',
                    font=cls.FONT_10,
                    size=(5, 1)),
                cls.generate_add_btn('node_nb', 'add', size=(5, 1)),
            ],
            [
                sg.Button('Save and Close', key='save'),
                sg.Button('Cancel', key='cancel'),
            ]
        ] 
Example #12
Source File: Demo_Desktop_Floating_Toolbar.py    From PySimpleGUI with GNU Lesser General Public License v3.0 5 votes vote down vote up
def Launcher():

    # def print(line):
    #     window.FindElement('output').Update(line)

    sg.ChangeLookAndFeel('Dark')

    namesonly = [f for f in os.listdir(ROOT_PATH) if f.endswith('.py') ]

    if len(namesonly) == 0:
        namesonly = ['test 1', 'test 2', 'test 3']

    sg.SetOptions(element_padding=(0,0), button_element_size=(12,1), auto_size_buttons=False)

    layout =  [[sg.Combo(values=namesonly, size=(35,30), key='demofile'),
                sg.Button('Run', button_color=('white', '#00168B')),
                sg.Button('Program 1'),
                sg.Button('Program 2'),
                sg.Button('Program 3', button_color=('white', '#35008B')),
                sg.Button('EXIT', button_color=('white','firebrick3'))],
                [sg.T('', text_color='white', size=(50,1), key='output')]]

    window = sg.Window('Floating Toolbar', no_titlebar=True, grab_anywhere=True, keep_on_top=True).Layout(layout)


    # ---===--- Loop taking in user input and executing appropriate program --- #
    while True:
        (event, values) = window.Read()
        if event == 'EXIT' or event is None:
            break           # exit button clicked
        if event == 'Program 1':
            print('Run your program 1 here!')
        elif event == 'Program 2':
            print('Run your program 2 here!')
        elif event == 'Run':
            file = values['demofile']
            print('Launching %s'%file)
            ExecuteCommandSubprocess('python', os.path.join(ROOT_PATH, file))
        else:
            print(event) 
Example #13
Source File: Demo_Youtube-dl_Frontend.py    From PySimpleGUI with GNU Lesser General Public License v3.0 5 votes vote down vote up
def DownloadSubtitlesGUI():
    sg.theme('Dark')

    combobox = sg.Combo(values=['', ], size=(10, 1), key='lang')
    layout = [
        [sg.Text('Subtitle Grabber', size=(40, 1), font=('Any 15'))],
        [sg.Text('YouTube Link'), sg.Input(default_text='', size=(60, 1), key='link')],
        [sg.Output(size=(90, 20), font='Courier 12')],
        [sg.Button('Get List')],
        [sg.Text('Language Code'), combobox, sg.Button('Download')],
        [sg.Button('Exit', button_color=('white', 'firebrick3'))]
    ]

    window = sg.Window('Subtitle Grabber launcher', layout,
                       text_justification='r',
                       default_element_size=(15, 1),
                       font=('Any 14'))

    # ---===--- Loop taking in user input and using it to query HowDoI --- #
    while True:
        event, values = window.read()
        if event in ('Exit', None):
            break           # exit button clicked
        link = values['link']
        if event == 'Get List':
            print('Getting list of subtitles....')
            window.refresh()
            command = [youtube_executable + f' --list-subs {link}']
            output = ExecuteCommandSubprocess(command, wait=True, quiet=True)
            lang_list = [o[:5].rstrip()
                         for o in output.split('\n') if 'vtt' in o]
            lang_list = sorted(lang_list)
            combobox.update(values=lang_list)
            print('Done')

        elif event == 'Download':
            lang = values['lang'] or 'en'
            print(f'Downloading subtitle for {lang}...')
            window.refresh()
            command = [youtube_executable + f' --sub-lang {lang} --write-sub {link}', ]
            print(ExecuteCommandSubprocess(command, wait=True, quiet=False))
            print('Done')
    window.close() 
Example #14
Source File: Demo_Desktop_Floating_Toolbar.py    From PySimpleGUI with GNU Lesser General Public License v3.0 5 votes vote down vote up
def Launcher():

    sg.theme('Dark')

    namesonly = [f for f in os.listdir(ROOT_PATH) if f.endswith('.py')]

    if len(namesonly) == 0:
        namesonly = ['test 1', 'test 2', 'test 3']

    sg.set_options(element_padding=(0, 0),
        button_element_size=(12, 1), auto_size_buttons=False)

    layout = [[sg.Combo(values=namesonly, size=(35, 30), key='demofile'),
               sg.Button('Run', button_color=('white', '#00168B')),
               sg.Button('Program 1'),
               sg.Button('Program 2'),
               sg.Button('Program 3', button_color=('white', '#35008B')),
               sg.Button('EXIT', button_color=('white', 'firebrick3'))],
              [sg.Text('', text_color='white', size=(50, 1), key='output')]]

    window = sg.Window('Floating Toolbar',
                       layout,
                       no_titlebar=True,
                       grab_anywhere=True,
                       keep_on_top=True)

    # ---===--- Loop taking in user input and executing appropriate program --- #
    while True:
        event, values = window.read()
        if event == 'EXIT' or event == sg.WIN_CLOSED:
            break           # exit button clicked
        if event == 'Program 1':
            print('Run your program 1 here!')
        elif event == 'Program 2':
            print('Run your program 2 here!')
        elif event == 'Run':
            file = values['demofile']
            print('Launching %s' % file)
            ExecuteCommandSubprocess('python', os.path.join(ROOT_PATH, file))
        else:
            print(event)

    window.close() 
Example #15
Source File: config_pvp.py    From kcauto with GNU General Public License v3.0 5 votes vote down vote up
def get_layout(cls):
        return sg.Column(
            [
                [
                    sg.Text('PvP Module', **cls.LABEL_SETTINGS),
                    sg.Checkbox(
                        'Enabled',
                        key='pvp.enabled',
                        enable_events=True)
                ],
                [
                    sg.Text('Fleet Preset', **cls.LABEL_SETTINGS),
                    sg.Combo(
                        [''] + [x for x in range(1, MAX_FLEET_PRESETS + 1)],
                        key='pvp.fleet_preset',
                        font=cls.FONT_10,
                        size=(13, 1))
                ]
            ],
            key='config_pvp_col',
            visible=False) 
Example #16
Source File: config_event_reset.py    From kcauto with GNU General Public License v3.0 5 votes vote down vote up
def get_layout(cls):
        return sg.Column(
            [
                [
                    sg.Text('Event Reset Module', **cls.LABEL_SETTINGS),
                    sg.Checkbox(
                        'Enabled',
                        key='event_reset.enabled',
                        enable_events=True)
                ],
                [
                    sg.Text('Reset Frequency', **cls.LABEL_SETTINGS),
                    sg.Spin(
                        [x for x in range(1, 11)],
                        2,
                        key='event_reset.frequency',
                        font=cls.FONT_10,
                        size=(4, 1))
                ],
                [
                    sg.Text('Reset Difficulty', **cls.LABEL_SETTINGS),
                    sg.Combo(
                        [
                            x.display_name for x in EventDifficultyEnum
                            if x is not EventDifficultyEnum.NONE],
                        default_value=EventDifficultyEnum.NORMAL.display_name,
                        key='event_reset.reset_difficulty',
                        font=cls.FONT_10,
                        size=(8, 1))
                ],
                [
                    sg.Text('Farm Difficulty', **cls.LABEL_SETTINGS),
                    sg.Combo(
                        [
                            x.display_name for x in EventDifficultyEnum
                            if x is not EventDifficultyEnum.NONE],
                        default_value=EventDifficultyEnum.EASY.display_name,
                        key='event_reset.farm_difficulty',
                        font=cls.FONT_10,
                        size=(8, 1))
                ]
            ],
            key='config_event_reset_col',
            visible=False)