Skip to content

Commit a130079

Browse files
Initial Checkin
1 parent b23b48a commit a130079

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import PySimpleGUIWeb as sg
2+
import random
3+
import string
4+
5+
# ------------------ Create a fake table ------------------
6+
class Fake():
7+
@classmethod
8+
def word(self):
9+
return ''.join(random.choice(string.ascii_lowercase) for i in range(10))
10+
11+
@classmethod
12+
def number(self, max=1000):
13+
return random.randint(0,max)
14+
15+
16+
def make_table(num_rows, num_cols):
17+
data = [[j for j in range(num_cols)] for i in range(num_rows)]
18+
data[0] = [Fake.word() for _ in range(num_cols)]
19+
for i in range(1, num_rows):
20+
data[i] = [Fake.word(), *[Fake.number() for i in range(num_cols - 1)]]
21+
return data
22+
23+
table_data = make_table(num_rows=15, num_cols=6)
24+
25+
# ------------------ Create a window layout ------------------
26+
layout = [[sg.Table(values=table_data,
27+
enable_events=True,
28+
display_row_numbers=True,
29+
font='Courier 14',
30+
row_header_text='Row #',
31+
key='_table_',
32+
text_color='red')],
33+
[sg.Button('Exit')],
34+
[sg.T('Selected rows = '), sg.T('', size=(30,1), key='_selected_rows_')],
35+
[sg.T('Selected value = '), sg.T('', size=(30,1), key='_selected_value_')]]
36+
37+
# ------------------ Create the window ------------------
38+
window = sg.Window('Table Element Example').Layout(layout)
39+
40+
# ------------------ The Event Loop ------------------
41+
while True:
42+
event, values = window.Read()
43+
if event in (None, 'Exit'):
44+
break
45+
window.Element('_selected_rows_').Update(values['_table_'])
46+
window.Element('_selected_value_').Update(window.Element('_table_').SelectedItem)
47+
# ------------------ User closed window so exit ------------------
48+
window.Close()

0 commit comments

Comments
 (0)