2018-10-04 23:42:25 +00:00
|
|
|
#!/usr/bin/env python
|
2022-07-03 20:33:51 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
Demo - Simple Tabs
|
|
|
|
|
|
|
|
How to use the Tab Element and the TabGroup Element
|
|
|
|
|
|
|
|
Copyright 2021 PySimpleGUI
|
|
|
|
"""
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
2019-12-24 23:52:47 +00:00
|
|
|
# Simple example of TabGroup element and the options available to it
|
|
|
|
sg.theme('Dark Red') # Please always add color to your window
|
|
|
|
# The tab 1, 2, 3 layouts - what goes inside the tab
|
2019-10-23 20:10:03 +00:00
|
|
|
tab1_layout = [[sg.Text('Tab 1')],
|
|
|
|
[sg.Text('Put your layout in here')],
|
2019-12-24 23:52:47 +00:00
|
|
|
[sg.Text('Input something'), sg.Input(size=(12,1), key='-IN-TAB1-')]]
|
2018-10-04 23:42:25 +00:00
|
|
|
|
2019-12-07 03:37:06 +00:00
|
|
|
tab2_layout = [[sg.Text('Tab 2')]]
|
|
|
|
tab3_layout = [[sg.Text('Tab 3')]]
|
2019-12-24 23:52:47 +00:00
|
|
|
tab4_layout = [[sg.Text('Tab 3')]]
|
2018-10-04 23:42:25 +00:00
|
|
|
|
2019-12-24 23:52:47 +00:00
|
|
|
# The TabgGroup layout - it must contain only Tabs
|
2022-07-03 20:33:51 +00:00
|
|
|
tab_group_layout = [[sg.Tab('Tab 1', tab1_layout, key='-TAB1-'),
|
2019-12-07 03:37:06 +00:00
|
|
|
sg.Tab('Tab 2', tab2_layout, visible=False, key='-TAB2-'),
|
2019-12-24 23:52:47 +00:00
|
|
|
sg.Tab('Tab 3', tab3_layout, key='-TAB3-'),
|
2022-07-03 20:33:51 +00:00
|
|
|
sg.Tab('Tab 4', tab4_layout, visible=False, key='-TAB4-')]]
|
2019-12-24 23:52:47 +00:00
|
|
|
|
|
|
|
# The window layout - defines the entire window
|
2019-12-07 03:37:06 +00:00
|
|
|
layout = [[sg.TabGroup(tab_group_layout,
|
|
|
|
enable_events=True,
|
|
|
|
key='-TABGROUP-')],
|
2022-07-03 20:33:51 +00:00
|
|
|
[sg.Text('Make tab number'), sg.Input(key='-IN-', size=(3,1)), sg.Button('Invisible'), sg.Button('Visible'), sg.Button('Select'), sg.Button('Disable')]]
|
2018-10-04 23:42:25 +00:00
|
|
|
|
2019-12-24 23:52:47 +00:00
|
|
|
window = sg.Window('My window with tabs', layout, no_titlebar=False)
|
2018-10-04 23:42:25 +00:00
|
|
|
|
2019-12-24 23:52:47 +00:00
|
|
|
tab_keys = ('-TAB1-','-TAB2-','-TAB3-', '-TAB4-') # map from an input value to a key
|
2018-10-04 23:42:25 +00:00
|
|
|
while True:
|
2019-12-24 23:52:47 +00:00
|
|
|
event, values = window.read() # type: str, dict
|
2019-12-07 03:37:06 +00:00
|
|
|
print(event, values)
|
2020-05-07 10:22:59 +00:00
|
|
|
if event == sg.WIN_CLOSED:
|
2018-10-04 23:42:25 +00:00
|
|
|
break
|
2019-12-24 23:52:47 +00:00
|
|
|
# handle button clicks
|
2019-12-07 03:37:06 +00:00
|
|
|
if event == 'Invisible':
|
|
|
|
window[tab_keys[int(values['-IN-'])-1]].update(visible=False)
|
|
|
|
if event == 'Visible':
|
|
|
|
window[tab_keys[int(values['-IN-'])-1]].update(visible=True)
|
2020-02-10 17:06:15 +00:00
|
|
|
if event == 'Select':
|
|
|
|
window[tab_keys[int(values['-IN-'])-1]].select()
|
2022-07-03 20:33:51 +00:00
|
|
|
if event == 'Disable':
|
|
|
|
window[tab_keys[int(values['-IN-']) - 1]].update(disabled=True)
|
2019-10-23 20:10:03 +00:00
|
|
|
window.close()
|