def table_example():
    sg.SetOptions(auto_size_buttons=True)
    filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files", "*.csv"),))
    # --- populate table with file contents --- #
    if filename == '':
        sys.exit(69)
    data = []
    header_list = []
    button = sg.PopupYesNo('Does this file have column names already?')
    if filename is not None:
        try:
            df = pd.read_csv(filename, sep=',', engine='python', header=None)  # Header=None means you directly pass the columns names to the dataframe
            data = df.values.tolist()               # read everything else into a list of rows
            if button == 'Yes':                     # Press if you named your columns in the csv
                header_list = df.iloc[0].tolist()   # Uses the first row (which should be column names) as columns names
                data = df[1:].values.tolist()       # Drops the first row in the table (otherwise the header names and the first row will be the same)
            elif button == 'No':                    # Press if you didn't name the columns in the csv
                header_list = ['column' + str(x) for x in range(len(data[0]))]  # Creates columns names for each column ('column0', 'column1', etc)
        except:
            sg.PopupError('Error reading file')
            sys.exit(69)
    # sg.SetOptions(element_padding=(0, 0))

    col_layout = [[sg.Table(values=data, headings=header_list, display_row_numbers=True,
                            auto_size_columns=False, size=(None, len(data)))]]

    canvas_size = (13*10*len(header_list), 600)      # estimate canvas size - 13 pixels per char * 10 per column * num columns
    layout = [[sg.Column(col_layout, size=canvas_size, scrollable=True)]]

    window = sg.Window('Table', grab_anywhere=False)
    b, v = window.LayoutAndRead(layout)

    sys.exit(69)
Beispiel #2
0
def table_example():
    filename = sg.PopupGetFile('filename to open',
                               no_window=True,
                               file_types=(("CSV Files", "*.csv"), ))
    # --- populate table with file contents --- #
    if filename == '':
        sys.exit(69)
    data = []
    header_list = []
    button = sg.PopupYesNo('Does this file have column names already?')
    if filename is not None:
        with open(filename, "r") as infile:
            reader = csv.reader(infile)
            if button == 'Yes':
                header_list = next(reader)
            try:
                data = list(reader)  # read everything else into a list of rows
                if button == 'No':
                    header_list = [
                        'column' + str(x) for x in range(len(data[0]))
                    ]
            except:
                sg.PopupError('Error reading file')
                sys.exit(69)
    sg.SetOptions(element_padding=(0, 0))

    col_layout = [[
        sg.Table(values=data,
                 headings=header_list,
                 max_col_width=25,
                 auto_size_columns=True,
                 justification='right',
                 size=(None, len(data)))
    ]]

    canvas_size = (
        13 * 10 * len(header_list), 600
    )  # estimate canvas size - 13 pixels per char * 10 char per column * num columns
    layout = [
        [sg.Column(col_layout, size=canvas_size, scrollable=True)],
    ]

    window = sg.Window('Table', grab_anywhere=False).Layout(layout)
    b, v = window.Read()

    sys.exit(69)
def TableSimulation():
    """
    Display data in a table format
    """
    sg.SetOptions(element_padding=(0, 0))
    sg.PopupNoWait('Give it a few seconds to load please...', auto_close=True)

    menu_def = [
        ['File', ['Open', 'Save', 'Exit']],
        [
            'Edit',
            ['Paste', [
                'Special',
                'Normal',
            ], 'Undo'],
        ],
        ['Help', 'About...'],
    ]

    columm_layout = [[]]

    MAX_ROWS = 60
    MAX_COL = 10
    for i in range(MAX_ROWS):
        inputs = [sg.T('{}'.format(i), size=(4, 1), justification='right')] + [
            sg.In(size=(10, 1),
                  pad=(1, 1),
                  justification='right',
                  key=(i, j),
                  do_not_clear=True) for j in range(MAX_COL)
        ]
        columm_layout.append(inputs)

    layout = [
        [sg.Menu(menu_def)],
        [sg.T('Table Using Combos and Input Elements', font='Any 18')],
        [
            sg.
            T('Type in a row, column and value. The form will update the values in realtime as you type'
              ),
            sg.In(key='inputrow',
                  justification='right',
                  size=(8, 1),
                  pad=(1, 1),
                  do_not_clear=True),
            sg.In(key='inputcol',
                  size=(8, 1),
                  pad=(1, 1),
                  justification='right',
                  do_not_clear=True),
            sg.In(key='value',
                  size=(8, 1),
                  pad=(1, 1),
                  justification='right',
                  do_not_clear=True)
        ], [sg.Column(columm_layout, size=(800, 600), scrollable=True)]
    ]

    window = sg.Window('Table',
                       return_keyboard_events=True,
                       grab_anywhere=False).Layout(layout)

    while True:
        button, values = window.Read()
        # --- Process buttons --- #
        if button is None or button == 'Exit':
            break
        elif button == 'About...':
            sg.Popup('Demo of table capabilities')
        elif button == 'Open':
            filename = sg.PopupGetFile('filename to open',
                                       no_window=True,
                                       file_types=(("CSV Files", "*.csv"), ))
            # --- populate table with file contents --- #
            if filename is not None:
                with open(filename, "r") as infile:
                    reader = csv.reader(infile)
                    try:
                        data = list(
                            reader)  # read everything else into a list of rows
                    except:
                        sg.PopupError('Error reading file')
                        continue
                # clear the table
                [
                    window.FindElement((i, j)).Update('')
                    for j in range(MAX_COL) for i in range(MAX_ROWS)
                ]

                for i, row in enumerate(data):
                    for j, item in enumerate(row):
                        location = (i, j)
                        try:  # try the best we can at reading and filling the table
                            target_element = window.FindElement(location)
                            new_value = item
                            if target_element is not None and new_value != '':
                                target_element.Update(new_value)
                        except:
                            pass

        # if a valid table location entered, change that location's value
        try:
            location = (int(values['inputrow']), int(values['inputcol']))
            target_element = window.FindElement(location)
            new_value = values['value']
            if target_element is not None and new_value != '':
                target_element.Update(new_value)
        except:
            pass
sg.ChangeLookAndFeel('LightGreen')
figure_w, figure_h = 650, 650
# define the form layout
listbox_values = [key for key in fig_dict.keys()]
col_listbox = [[
    sg.Listbox(values=listbox_values,
               change_submits=True,
               size=(28, len(listbox_values)),
               key='func')
], [sg.T(' ' * 12), sg.Exit(size=(5, 2))]]

layout = [
    [sg.Text('Matplotlib Plot Test', font=('current 18'))],
    [
        sg.Column(col_listbox, pad=(5, (3, 330))),
        sg.Canvas(size=(figure_w, figure_h), key='canvas'),
        sg.Multiline(size=(70, 35), pad=(5, (3, 90)), key='multiline')
    ],
]

# create the form and show it without the plot
window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI',
                   grab_anywhere=False).Layout(layout)
window.Finalize()

canvas_elem = window.FindElement('canvas')
multiline_elem = window.FindElement('multiline')

while True:
    button, values = window.Read()
Beispiel #5
0
        sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'),
                   size=(30, 3)),
        sg.Frame('Labelled Group', [[
            sg.Slider(range=(1, 100),
                      orientation='v',
                      size=(5, 20),
                      default_value=25),
            sg.Slider(range=(1, 100),
                      orientation='v',
                      size=(5, 20),
                      default_value=75),
            sg.Slider(range=(1, 100),
                      orientation='v',
                      size=(5, 20),
                      default_value=10),
            sg.Column(column1, background_color='#F7F3EC')
        ]])
    ], [sg.Text('_' * 80)], [sg.Text('Choose A Folder', size=(35, 1))],
    [
        sg.Text('Your Folder',
                size=(15, 1),
                auto_size_text=False,
                justification='right'),
        sg.InputText('Default Folder'),
        sg.FolderBrowse()
    ], [sg.Submit(tooltip='Click to submit this form'),
        sg.Cancel()]
]

window = sg.Window('Everything bagel',
                   default_element_size=(40, 1),
Beispiel #6
0
data = []
if filename is not None:
    with open(filename, "r") as infile:
        reader = csv.reader(infile)
        try:
            data = list(reader)  # read everything else into a list of rows
        except:
            sg.PopupError('Error reading file')
            sys.exit(69)

sg.SetOptions(element_padding=(0, 0))

col_layout = [[
    sg.Table(values=data[1:][:],
             headings=[data[0][x] for x in range(len(data[0]))],
             max_col_width=25,
             auto_size_columns=True,
             display_row_numbers=True,
             justification='right',
             size=(None, len(data)))
]]

layout = [
    [sg.Column(col_layout, size=(1200, 600), scrollable=True)],
]
window = sg.Window('Table', grab_anywhere=False).Layout(layout)

b, v = window.Read()

sys.exit(69)
Beispiel #7
0
def Everything():
    sg.ChangeLookAndFeel('TanBlue')

    column1 = [[
        sg.Text('Column 1',
                background_color=sg.DEFAULT_BACKGROUND_COLOR,
                justification='center',
                size=(10, 1))
    ],
               [
                   sg.Spin(values=('Spin Box 1', '2', '3'),
                           initial_value='Spin Box 1',
                           key='spin1')
               ],
               [
                   sg.Spin(values=('Spin Box 1', '2', '3'),
                           initial_value='Spin Box 2',
                           key='spin2')
               ],
               [
                   sg.Spin(values=('Spin Box 1', '2', '3'),
                           initial_value='Spin Box 3',
                           key='spin3')
               ]]

    layout = [
        [
            sg.Text('All graphic widgets in one form!',
                    size=(30, 1),
                    font=("Helvetica", 25))
        ], [sg.Text('Here is some text.... and a place to enter text')],
        [sg.InputText('This is my text', key='in1', do_not_clear=True)],
        [
            sg.Checkbox('Checkbox', key='cb1'),
            sg.Checkbox('My second checkbox!', key='cb2', default=True)
        ],
        [
            sg.Radio('My first Radio!     ',
                     "RADIO1",
                     key='rad1',
                     default=True),
            sg.Radio('My second Radio!', "RADIO1", key='rad2')
        ],
        [
            sg.Multiline(
                default_text=
                'This is the default Text should you decide not to type anything',
                size=(35, 3),
                key='multi1',
                do_not_clear=True),
            sg.Multiline(default_text='A second multi-line',
                         size=(35, 3),
                         key='multi2',
                         do_not_clear=True)
        ],
        [
            sg.InputCombo(('Combobox 1', 'Combobox 2'),
                          key='combo',
                          size=(20, 1)),
            sg.Slider(range=(1, 100),
                      orientation='h',
                      size=(34, 20),
                      key='slide1',
                      default_value=85)
        ],
        [
            sg.InputOptionMenu(
                ('Menu Option 1', 'Menu Option 2', 'Menu Option 3'),
                key='optionmenu')
        ],
        [
            sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'),
                       size=(30, 3),
                       key='listbox'),
            sg.Slider(
                range=(1, 100),
                orientation='v',
                size=(5, 20),
                default_value=25,
                key='slide2',
            ),
            sg.Slider(
                range=(1, 100),
                orientation='v',
                size=(5, 20),
                default_value=75,
                key='slide3',
            ),
            sg.Slider(range=(1, 100),
                      orientation='v',
                      size=(5, 20),
                      default_value=10,
                      key='slide4'),
            sg.Column(column1, background_color='gray34')
        ], [sg.Text('_' * 80)], [sg.Text('Choose A Folder', size=(35, 1))],
        [
            sg.Text('Your Folder',
                    size=(15, 1),
                    auto_size_text=False,
                    justification='right'),
            sg.InputText('Default Folder', key='folder', do_not_clear=True),
            sg.FolderBrowse()
        ],
        [
            sg.ReadButton('Exit'),
            sg.Text(' ' * 40),
            sg.ReadButton('SaveSettings'),
            sg.ReadButton('LoadSettings')
        ]
    ]

    window = sg.Window('Form Fill Demonstration',
                       default_element_size=(40, 1),
                       grab_anywhere=False)
    # button, values = window.LayoutAndRead(layout, non_blocking=True)
    window.Layout(layout)

    while True:
        button, values = window.Read()

        if button is 'SaveSettings':
            filename = sg.PopupGetFile('Save Settings',
                                       save_as=True,
                                       no_window=True)
            window.SaveToDisk(filename)
            # save(values)
        elif button is 'LoadSettings':
            filename = sg.PopupGetFile('Load Settings', no_window=True)
            window.LoadFromDisk(filename)
            # load(form)
        elif button in ['Exit', None]:
            break
Beispiel #8
0
                     sg.TabGroup([[
                         sg.Tab('Tab 1', tab1_layout),
                         sg.Tab('Tab 2', tab2_layout)
                     ]]),
                     sg.TabGroup([[
                         sg.Tab('Tab3', tab3_layout),
                         sg.Tab('Tab 4', tab4_layout)
                     ]])
                 ]])
    ],
    [
        sg.T('This text is on a row with a column'),
        sg.Column(layout=[[sg.T('In a column')],
                          [
                              sg.TabGroup([[
                                  sg.Tab('Tab 5', tab5_layout),
                                  sg.Tab('Tab 6', tab6_layout)
                              ]])
                          ], [sg.RButton('Click me')]])
    ],
]

window = sg.Window('My window with tabs',
                   default_element_size=(12, 1)).Layout(layout).Finalize()

print('Are there enough tabs for you?')

while True:
    button, values = window.Read()
    print(button, values)
    if button is None:  # always,  always give a way out!
Beispiel #9
0
    sg.Popup('No PNG images in folder')
    exit(0)


# define menu layout
menu = [['File', ['Open Folder', 'Exit']], ['Help', ['About',]]]

# define layout, show and read the window
col = [[sg.Text(png_files[0], size=(80, 3), key='filename')],
          [sg.Image(filename=png_files[0], key='image')],
          [sg.ReadButton('Next', size=(8,2)), sg.ReadButton('Prev', size=(8,2)),
           sg.Text('File 1 of {}'.format(len(png_files)), size=(15,1), key='filenum')]]

col_files = [[sg.Listbox(values=filenames_only, size=(60,30), key='listbox')],
             [sg.ReadButton('Read')]]
layout = [[sg.Menu(menu)], [sg.Column(col_files), sg.Column(col)]]
window = sg.Window('Image Browser', return_keyboard_events=True, location=(0,0), use_default_focus=False ).Layout(layout)

# loop reading the user input and displaying image, filename
i=0
while True:

    button, values = window.Read()
    # --------------------- Button & Keyboard ---------------------
    if button is None:
        break
    elif button in ('Next', 'MouseWheel:Down', 'Down:40', 'Next:34') and i < len(png_files)-1:
        i += 1
    elif button in ('Prev', 'MouseWheel:Up', 'Up:38', 'Prior:33') and i > 0:
        i -= 1
    elif button == 'Exit':
Beispiel #10
0
# define layout, show and read the form
col = [[filename_display_elem], [image_elem]]

col_files = [[
    sg.Listbox(values=fnames,
               change_submits=True,
               size=(60, 30),
               key='listbox')
],
             [
                 sg.ReadButton('Next', size=(8, 2)),
                 sg.ReadButton('Prev', size=(8, 2)), file_num_display_elem
             ]]

layout = [[sg.Column(col_files), sg.Column(col)]]

window.Layout(layout)  # Shows form on screen

# loop reading the user input and displaying image, filename
i = 0
while True:
    # read the form
    button, values = window.Read()

    # perform button and keyboard operations
    if button is None:
        break
    elif button in ('Next', 'MouseWheel:Down', 'Down:40', 'Next:34'):
        i += 1
        if i >= num_files:
Beispiel #11
0
#!/usr/bin/env python
import sys
if sys.version_info[0] < 3:
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg

sg.ChangeLookAndFeel('BlueMono')

# Column layout
col = [[sg.Text('col Row 1', text_color='white', background_color='blue')],
       [sg.Text('col Row 2', text_color='white', background_color='blue'), sg.Input('col input 1')],
       [sg.Text('col Row 3', text_color='white', background_color='blue'), sg.Input('col input 2')]]
# Window layout
layout = [[sg.Listbox(values=('Listbox Item 1', 'Listbox Item 2', 'Listbox Item 3'),
                      select_mode=sg.LISTBOX_SELECT_MODE_MULTIPLE, size=(20, 3)),
           sg.Column(col, background_color='blue')],
          [sg.Input('Last input')],
          [sg.OK()]]

# Display the window and get values
button, values = sg.Window('Compact 1-line form with column').Layout(layout).Read()

sg.Popup(button, values, line_width=200)