def value_ele(value: Any, val_key: str, disabled: bool, list_width: int = 30, no_add: bool = False, **kwargs) -> Element: if isinstance(value, bool): val_ele = Checkbox('', default=value, key=val_key, disabled=disabled, pad=(0, 0), **kwargs) elif isinstance(value, list): kwargs.setdefault('tooltip', 'Unselected items will not be saved') add_button = not no_add and val_key.startswith('val::') if not add_button: kwargs.setdefault('pad', (6, 0)) val_ele = Listbox( value, default_values=value, key=val_key, disabled=disabled, size=(list_width, len(value)), no_scrollbar=True, select_mode='extended', # extended, browse, single, multiple **kwargs, ) if add_button: val_ele = Column( [[ val_ele, Button('Add...', key=val_key.replace('val::', 'add::', 1), disabled=disabled, pad=(0, 0)) ]], key=f'col::{val_key}', pad=(0, 0), vertical_alignment='center', justification='center', expand_y=True, expand_x=True, ) else: val_ele = ExtInput(value, key=val_key, disabled=disabled, right_click_menu=SearchMenu(), **kwargs) return val_ele
def _generate_layout( self, disable_all: bool) -> Iterator[tuple[Optional[int], int, Element]]: for name, opt in self.options.items(): opt_type, col_num, row_num = opt['opt_type'], opt['col'], opt[ 'row'] val = opt.get('value', opt['default']) disabled = disable_all or opt['disabled'] common = {'key': f'opt::{name}', 'disabled': disabled} if opt_kwargs := opt.get('kwargs'): common.update(opt_kwargs) for param in COMMON_PARAMS: try: common[param] = opt[param] except KeyError: pass if opt_type == 'checkbox': yield col_num, row_num, Checkbox(opt['label'], default=val, **common) elif opt_type == 'input': yield col_num, row_num, Text(opt['label'], key=f'lbl::{name}') yield col_num, row_num, ExtInput('' if val is _NotSet else val, **common) elif opt_type == 'dropdown': yield col_num, row_num, Text(opt['label'], key=f'lbl::{name}') yield col_num, row_num, Combo(opt['choices'], default_value=val, **common) elif opt_type == 'listbox': choices = opt['choices'] yield col_num, row_num, Text(opt['label'], key=f'lbl::{name}') yield col_num, row_num, Listbox(choices, default_values=val or choices, no_scrollbar=True, select_mode=opt['select_mode'], **common) if opt['extendable']: yield col_num, row_num, Button('Add...', key=f'btn::{name}', disabled=disabled) elif opt_type == 'path': val = val.as_posix() if isinstance( val, Path) else None if val is _NotSet else val yield col_num, row_num, Text(opt['label'], key=f'lbl::{name}') yield col_num, row_num, ExtInput('' if val is None else val, **common) yield col_num, row_num, opt['button_func'](initial_folder=val) else: raise ValueError(f'Unsupported {opt_type=!r}')
def getList(prompt: str, items: list) -> str: win: Window = Window(alpha_channel=0.8, finalize=True, debugger_enabled=False, resizable=True, text_justification="center", title=prompt.strip(), no_titlebar=True, keep_on_top=True, disable_close=True, disable_minimize=True, grab_anywhere=True, auto_size_text=True, layout=[ [Text(text=prompt.strip(), expand_x=True, expand_y=True, auto_size_text=True)], [Listbox( values=items, select_mode=LISTBOX_SELECT_MODE_SINGLE, enable_events=True, auto_size_text=True, expand_x=True, expand_y=True, size=(32, 16) )], [Text(text="Made By: TonicBoomerKewl", expand_x=True, expand_y=True, auto_size_text=True)] ]) focus(win) res = win.read() win.close() try: return res[1][0][0] except IndexError: return ''
Demo Columns and Frames Demonstrates using mixture of Column and Frame elements to create a nice window layout. A couple of the concepts shown here include: * Using Columns and Frames with specific sizes on them * Importing all required classes so that "sg." is not required on any objects. This makes the code more compact and readable There are 3 columns. Two are side by side at the top and the third is along the bottom """ sg.theme('GreenTan') col2 = Column([[ Frame('Accounts:', [[ Column([[ Listbox(['Account ' + str(i) for i in range(1, 16)], key='-ACCT-LIST-', size=(15, 20)), ]], size=(150, 400)) ]]) ]], pad=(0, 0)) col1 = Column( [ # Categories frame [ Frame( 'Categories:', [[ Radio('Websites',
def start(): Gui._info_text = Text(background_color='#101010', font=(None, 18, 'italic'), justification='c', key='info_text', border_width=8, size=(24, 1), text='Enter sensor address') Gui._address_input = Input(default_text='192.168.0.', key='address_input', size=(16, 1)) Gui._load_button = Button(bind_return_key=True, button_text='Load', key='load_button', size=(6, 1)) Gui._file_list = Listbox(values=(), background_color='#e0e4f0', enable_events=True, highlight_background_color='#a0c0e0', highlight_text_color='#000000', key='file_list', select_mode=PySimpleGUI.SELECT_MODE_MULTIPLE, size=(28, 12), text_color='#202020') Gui._selection_text = Text(background_color='#101010', font=(None, 14, 'italic'), justification='c', key='selection_text', size=(24, 1), text_color='#808080') Gui._select_all_button = Button(button_text='Select All', disabled=True, key='select_all_button', size=(12, 1)) Gui._deselect_all_button = Button(button_text='Deselect All', disabled=True, key='deselect_all_button', size=(12, 1)) Gui._retrieve_button = PySimpleGUI.FolderBrowse(button_text='Retrieve', disabled=True, key='retrieve_button', size=(12, 1), target='retrieve_button_handle') # FolderBrowser is buggy at reporting events Gui._retrieve_button_handle = Button(enable_events=True, key='retrieve_button_handle', visible=False) Gui._delete_button = Button(button_text='Delete', disabled=True, key='delete_button', size=(12, 1)) Gui._is_element_disabled = { x: False for x in (Gui._address_input, Gui._load_button, Gui._file_list, Gui._select_all_button, Gui._deselect_all_button, Gui._retrieve_button, Gui._delete_button) } Gui._window = Window(background_color='#101010', element_justification='c', element_padding=(9, 9), font=(None, 16), layout=( (Gui._info_text,), (Gui._address_input, Gui._load_button), (Gui._file_list,), (Gui._selection_text,), (Gui._select_all_button, Gui._deselect_all_button), (Gui._retrieve_button, Gui._delete_button), (Gui._retrieve_button_handle,), ), margins=(48, 48), title='Retrieve Data From Sensor') Gui._window.finalize() Gui._address_input.update(select=True) Gui._address_input.set_focus(True) while True: event, values = Gui._window.read() if event == PySimpleGUI.WIN_CLOSED: break Gui._address_input_value = values['address_input'] Gui._file_list_selection = values['file_list'] Gui._retrieve_button_selection = values['retrieve_button'] if event == 'load_button': Gui._handle_load_button_clicked() elif event == 'file_list': Gui._handle_file_list_selected() elif event == 'select_all_button': Gui._handle_select_all_button_clicked() elif event == 'deselect_all_button': Gui._handle_deselect_all_button_clicked() elif event == 'retrieve_button_handle': Gui._handle_retrieve_button_selected() elif event == 'delete_button': Gui._handle_delete_button_clicked() else: print('Unhandled:', event, values)
# layout for friend badges friend_badges_layout = [ [Frame('Badges', friends_badges_frame, font=('Courier', 12, 'bold'), background_color=sg.theme_input_background_color())] ] goals_frame = [ [Text("\n COMPLETED GOALS", font=('Courier', 12), size=(33, 3), justification='centre', border_width=0)], ] button_new_goal_frame = [ # add goal button [Button(button_color=(sg.theme_background_color(), sg.theme_background_color()), image_filename=r'plus_icon.png', border_width=0, key='-ADD_GOAL-', image_size=(15, 15)), Text('New Goal', font=('Courier', 12))], ] completed_goals = [ [Listbox(values=[], enable_events=True, size= (40,5), font=("Courier", 10), key="-COMPLETED_GOALS_LIST-")] ] incomplete_goal_frame = [ # add goal button [Text("\n CURRENT GOALS", font=('Courier', 12), size=(33, 3), justification='centre', border_width=0)], ] timer_button_and_goals = [ # listing the goals [Listbox(values=[], enable_events=True, size=(40, 20), font=('Courier', 10), key='-GOALS_LIST-', background_color='#E0DEDE'), Button(button_color=(sg.theme_background_color(), sg.theme_background_color()), border_width=0, image_filename='big_alarm_clock.png', key='-TIMER_BUTTON-')], ]
window = sg.Window("Shortcuts", layout) event, values = window.read() sg.popup_scrolled(event, values) window.close() col2 = Column( [[ Frame( "Accounts:", [[ Column( [[ Listbox( ["Account " + str(i) for i in range(1, 16)], key="-ACCT-LIST-", size=(15, 20), select_mode=sg.LISTBOX_SELECT_MODE_EXTENDED, ), ]], size=(150, 400), ) ]], ) ]], pad=(0, 0), ) col1 = Column( [ # Categories frame [
radio_team_analysis = 3 radio_performance = 4 radio_team_choice = 5 def leagues() -> List[str]: options = [] for key in list(league_register.keys()): league = league_register[key] options.append('{} {}'.format(league.country, league.name)) return options league_choice = Listbox(leagues(), size=(34, 16), font=font, enable_events=True, key='-LEAGUE-') history_choice = Slider(range=(history_min, history_max), default_value=history_max, orientation='h', font=font, key='-HISTORY-') team_radio_one = Radio('', radio_team_choice, font=font, default=True) team_radio_two = Radio('', radio_team_choice, font=font) team_choice_one = InputText(font=font, size=(30, 1), key='-TEAM1-') team_choice_two = InputText(font=font, size=(30, 1), key='-TEAM2-') team_clear_one = Button('Clear', button_color=('black', 'white'),
coluna_detalhes = [[Text('', key='nome', size=(30, 1), pad=(1,5))], [Text('', key='telefone', size=(30, 1), pad=(1,8))], [Text('', key='celular', size=(30, 1), pad=(1,8))], [Text('', key='email', size=(30, 1), pad=(1,8))], [Text('', key='vivencia', size=(30, 1), pad=(1,8))], [Text('', key='data', size=(30, 1), pad=(1,8))], [Text('', key='item', size=(30, 1), pad=(1,8))] ] coluna_btt = [[Button('Editar', key='Editar',pad=(10,0,5), size=(8,1), button_color=('white', 'springgreen4')), Button('Apagar', key='Apagar', size=(8,1), button_color=('white', 'firebrick3'))]] coluna_bt1 = [[Button("Cadastrar",button_color=('white', 'springgreen4'), size=(8,1)), Button("Sair", button_color=('white', 'firebrick3'), size=(8,1), pad=(10,0))]] coluna_nomes = [[Button('Buscar', size=(8,1), pad=(25,1), button_color=('white', 'springgreen4')), Button("", key='botao_busca', visible=False, size=(12,1), button_color=('white', 'firebrick3'))], [Text("", size=(30,2), justification=('center'), key='buscas')], [Listbox(values= NOMES, key='lista', change_submits=True, size=(130, 100))]] tela_principal = [[Frame("Loans-Management", coluna_detalhes), Column(coluna_nomes, size=(130,100))], [Column(coluna_bt1, key='Apag', visible=True)], [Column(coluna_btt, key='Edit', visible=False)] ] janela = Window("Loans-Management", size=(600, 350), icon=('C:\\Loans-management\\Icon\\icon-logo.ico'), text_justification=('center')).Layout(tela_principal) while True: evento, valores = janela.Read() if evento == 'lista': try: nome = valores['lista'][0] emprestimo = buscar_nome(nome) nome = "Nome: " + emprestimo['nome'] telefone = "Telefone: " + emprestimo['telefone'] celular = "Celular: " + emprestimo['celular'] email = "E-mail: " + emprestimo['email']