Ejemplo n.º 1
0
def TestMenus():
    import PySimpleGUI as sg

    sg.ChangeLookAndFeel('LightGreen')
    sg.SetOptions(element_padding=(0, 0))

    # ------ Menu Definition ------ #
    menu_def = [
        ['File', ['Open', 'Save', 'Properties']],
        [
            'Edit',
            ['Paste', [
                'Special',
                'Normal',
            ], 'Undo'],
        ],
        ['Help', 'About...'],
    ]

    # ------ GUI Defintion ------ #
    layout = [[sg.Menu(menu_def, tearoff=True)], [sg.Output(size=(60, 20))],
              [sg.In('Test', key='input', do_not_clear=True)]]

    window = sg.Window("Windows-like program",
                       default_element_size=(12, 1),
                       auto_size_text=False,
                       auto_size_buttons=False,
                       default_button_element_size=(12, 1)).Layout(layout)

    # ------ Loop & Process button menu choices ------ #
    while True:
        button, values = window.Read()
        if button is None or button == 'Exit':
            return
        print('Button = ', button)
        # ------ Process menu choices ------ #
        if button == 'About...':
            sg.Popup('About this program', 'Version 1.0',
                     'PySimpleGUI rocks...')
        elif button == 'Open':
            filename = sg.PopupGetFile('file to open', no_window=True)
            print(filename)
        elif button == 'Properties':
            SecondForm()
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
]

# ------ Column Definition ------ #
column1 = [
    [
        sg.Text('Column 1',
                background_color='#F7F3EC',
                justification='center',
                size=(10, 1))
    ], [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')],
    [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2')],
    [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3')]
]

layout = [
    [sg.Menu(menu_def, tearoff=True)],
    [
        sg.Text('All graphic widgets in one form!',
                size=(30, 1),
                justification='center',
                font=("Helvetica", 25),
                relief=sg.RELIEF_RIDGE)
    ], [sg.Text('Here is some text.... and a place to enter text')],
    [sg.InputText('This is my text')],
    [
        sg.Frame(layout=[[
            sg.Checkbox('Checkbox', size=(10, 1)),
            sg.Checkbox('My second checkbox!', default=True)
        ],
                         [
                             sg.Radio('My first Radio!     ',
Ejemplo n.º 4
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':