From 3a46858e199cc89ab2ee579af3ff085bf7439609 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Thu, 13 Sep 2018 12:13:27 -0400 Subject: [PATCH] New demo program that shows how to use the Table Element --- Demo_Table_Element.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Demo_Table_Element.py diff --git a/Demo_Table_Element.py b/Demo_Table_Element.py new file mode 100644 index 00000000..a095cc71 --- /dev/null +++ b/Demo_Table_Element.py @@ -0,0 +1,26 @@ +import csv +import PySimpleGUI as sg + +filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files","*.csv"),)) +# --- populate table with file contents --- # +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') + exit(69) + +sg.SetOptions(element_padding=(0, 0)) + +col_layout = [[sg.Table(values=data, headings=[x for x in range(len(data[0]))], max_col_width=8, + auto_size_columns=False, justification='right', size=(8, len(data)))]] + +layout = [[sg.Column(col_layout, size=(1200,600), scrollable=True)],] + +form = sg.FlexForm('Table', grab_anywhere=False) +b, v = form.LayoutAndRead(layout) + +exit(69)