def make_window(theme): sg.theme(theme) menu_def = [['&Application', ['E&xit']], ['&Help', ['&About']]] right_click_menu_def = [[], [ 'Edit Me', 'Versions', 'Nothing', 'More Nothing', 'Exit' ]] graph_right_click_menu_def = [[], [ 'Erase', 'Draw Line', 'Draw', ['Circle', 'Rectangle', 'Image'], 'Exit' ]] # Table Data data = [["John", 10], ["Jen", 5]] headings = ["Name", "Score"] input_layout = [ # [sg.Menu(menu_def, key='-MENU-')], [sg.Text('Anything that requires user-input is in this tab!')], [sg.Input(key='-INPUT-')], [ sg.Slider(orientation='h', key='-SKIDER-'), sg.Image(data=sg.DEFAULT_BASE64_LOADING_GIF, enable_events=True, key='-GIF-IMAGE-'), ], [sg.Checkbox('Checkbox', default=True, k='-CB-')], [ sg.Radio('Radio1', "RadioDemo", default=True, size=(10, 1), k='-R1-'), sg.Radio('Radio2', "RadioDemo", default=True, size=(10, 1), k='-R2-') ], [ sg.Combo(values=('Combo 1', 'Combo 2', 'Combo 3'), default_value='Combo 1', readonly=True, k='-COMBO-'), sg.OptionMenu(values=('Option 1', 'Option 2', 'Option 3'), k='-OPTION MENU-'), ], [ sg.Spin([i for i in range(1, 11)], initial_value=10, k='-SPIN-'), sg.Text('Spin') ], [ sg.Multiline( 'Demo of a Multi-Line Text Element!\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nYou get the point.', size=(45, 5), expand_x=True, expand_y=True, k='-MLINE-') ], [ sg.Button('Button'), sg.Button('Popup'), sg.Button(image_data=sg.DEFAULT_BASE64_ICON, key='-LOGO-') ] ] asthetic_layout = [[ sg.T('Anything that you would use for asthetics is in this tab!') ], [sg.Image(data=sg.DEFAULT_BASE64_ICON, k='-IMAGE-')], [ sg.ProgressBar(100, orientation='h', size=(20, 20), key='-PROGRESS BAR-'), sg.Button('Test Progress bar') ]] logging_layout = [ [sg.Text("Anything printed will display here!")], [ sg.Multiline(size=(60, 15), font='Courier 8', expand_x=True, expand_y=True, write_only=True, reroute_stdout=True, reroute_stderr=True, echo_stdout_stderr=True, autoscroll=True, auto_refresh=True) ] # [sg.Output(size=(60,15), font='Courier 8', expand_x=True, expand_y=True)] ] graphing_layout = [[ sg.Text("Anything you would use to graph will display here!") ], [ sg.Graph( (200, 200), (0, 0), (200, 200), background_color="black", key='-GRAPH-', enable_events=True, right_click_menu=graph_right_click_menu_def) ], [sg.T('Click anywhere on graph to draw a circle')], [ sg.Table(values=data, headings=headings, max_col_width=25, background_color='black', auto_size_columns=True, display_row_numbers=True, justification='right', num_rows=2, alternating_row_color='black', key='-TABLE-', row_height=25) ]] popup_layout = [[sg.Text("Popup Testing")], [sg.Button("Open Folder")], [sg.Button("Open File")]] theme_layout = [[ sg.Text( "See how elements look under different themes by choosing a different theme here!" ) ], [ sg.Listbox(values=sg.theme_list(), size=(20, 12), key='-THEME LISTBOX-', enable_events=True) ], [sg.Button("Set Theme")]] layout = [[ sg.MenubarCustom(menu_def, key='-MENU-', font='Courier 15', tearoff=True) ], [ sg.Text('Demo Of (Almost) All Elements', size=(38, 1), justification='center', font=("Helvetica", 16), relief=sg.RELIEF_RIDGE, k='-TEXT HEADING-', enable_events=True) ]] layout += [[ sg.TabGroup([[ sg.Tab('Input Elements', input_layout), sg.Tab('Asthetic Elements', asthetic_layout), sg.Tab('Graphing', graphing_layout), sg.Tab('Popups', popup_layout), sg.Tab('Theming', theme_layout), sg.Tab('Output', logging_layout) ]], key='-TAB GROUP-', expand_x=True, expand_y=True), ]] layout[-1].append(sg.Sizegrip()) window = sg.Window( 'All Elements Demo', layout, right_click_menu=right_click_menu_def, right_click_menu_tearoff=True, grab_anywhere=True, resizable=True, margins=(0, 0), use_custom_titlebar=True, finalize=True, keep_on_top=True, # scaling=2.0, ) window.set_min_size(window.size) return window
def main(): sg.theme('dark green 7') # sg.theme('dark gray 13') sg.theme('dark red') # sg.theme('black') menu_def = [ [ '&File', ['&Open Ctrl-O', '&Save Ctrl-S', '&Properties', 'E&xit'] ], [ '&Edit', ['Edit Me', 'Special', 'Normal', ['Normal1', 'Normal2'], 'Undo'] ], ['!Disabled', ['Special', 'Normal', ['Normal1', 'Normal2'], 'Undo']], [ '&Toolbar', [ '---', 'Command &1::Command_Key', 'Command &2', '---', 'Command &3', 'Command &4' ] ], ['&Help', ['&About...']], ] layout = [[sg.MenubarCustom(menu_def, pad=(0, 0), k='-CUST MENUBAR-')], [ sg.Multiline(size=(70, 20), reroute_cprint=True, write_only=True, no_scrollbar=True, k='-MLINE-') ]] window = sg.Window("Custom Titlebar with Custom (Simulated) Menubar", layout, use_custom_titlebar=True, keep_on_top=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT) # ------ Event Loop ------ # while True: event, values = window.read() # convert ButtonMenu event so they look like Menu events if event in (sg.WIN_CLOSED, 'Exit'): break sg.cprint(f'event = {event}', c=(sg.theme_background_color(), sg.theme_text_color())) sg.cprint(f'values = {values}', c=(sg.theme_input_text_color(), sg.theme_input_background_color())) # ------ Process menu choices ------ # if event == 'About...': window.disappear() sg.popup('About this program', 'Simulated Menubar to accompany a simulated Titlebar', 'PySimpleGUI Version', sg.get_versions(), grab_anywhere=True, keep_on_top=True) window.reappear() elif event == 'Edit Me': sg.execute_editor(__file__) elif event == 'Version': sg.popup_scrolled(__file__, sg.get_versions(), keep_on_top=True, non_blocking=True) elif event.startswith('Open'): filename = sg.popup_get_file('file to open', no_window=True) print(filename) window.close()