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 addClient():
    layout = [
        [sg.Text('Please enter the IP address and email')],
        [sg.Text('IP Address:', size=(15, 1)),
         sg.InputText('', key='_IP_')],
        [sg.Text('Email:', size=(15, 1)),
         sg.InputText('', key='_EMAIL_')], [sg.Submit(),
                                            sg.Cancel()]
    ]
    window = sg.Window('Add Account', layout)
    event, values = window.Read()
    window.Close()
    if (sg.PopupYesNo("Are you sure?") == "Yes"):
        return values
    else:
        pass
Beispiel #3
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)
Beispiel #4
0
def addAccount():  #add email account to the "Available" section
    layout = [[sg.Text('Please enter the email address and password')],
              [
                  sg.Text('Email Address:', size=(15, 1)),
                  sg.InputText('', key='_EMAIL_')
              ],
              [
                  sg.Text('Password:'******'', key='_PASSWORD_')
              ], [sg.Submit(), sg.Cancel()]]
    window = sg.Window('Add Account', layout)
    event, values = window.Read()
    window.Close()
    if (sg.PopupYesNo("Are you sure?") == "Yes"):
        return values
    else:
        pass
Beispiel #5
0
#!/usr/bin/env python
import sys
if sys.version_info[0] < 3:
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg

# Here, have some windows on me....
[sg.PopupNoWait(location=(10 * x, 0)) for x in range(10)]

print(sg.PopupYesNo('Yes No'))

print(sg.PopupGetText('Get text', location=(1000, 200)))
print(sg.PopupGetFile('Get file'))
print(sg.PopupGetFolder('Get folder'))

sg.Popup('Simple popup')

sg.PopupNonBlocking('Non Blocking', location=(500, 500))
sg.PopupNoTitlebar('No titlebar')
sg.PopupNoBorder('No border')
sg.PopupNoFrame('No frame')
# sg.PopupNoButtons('No Buttons')        # don't mix with non-blocking... disaster ahead...
sg.PopupCancel('Cancel')
sg.PopupOKCancel('OK Cancel')
sg.PopupAutoClose('Autoclose')