Demo updates with new theme calls
This commit is contained in:
parent
52700b0780
commit
5484b047c0
96 changed files with 3530 additions and 228 deletions
|
@ -3,40 +3,48 @@ import PySimpleGUI as sg
|
|||
import random
|
||||
import string
|
||||
|
||||
# Yet another example of showing CSV data in Table
|
||||
"""
|
||||
Basic use of the Table Element
|
||||
"""
|
||||
|
||||
sg.theme('Dark Red')
|
||||
|
||||
# ------ Some functions to help generate data for the table ------
|
||||
def word():
|
||||
return ''.join(random.choice(string.ascii_lowercase) for i in range(10))
|
||||
def number(max_val=1000):
|
||||
return random.randint(0, max_val)
|
||||
|
||||
|
||||
def make_table(num_rows, num_cols):
|
||||
data = [[j for j in range(num_cols)] for i in range(num_rows)]
|
||||
data[0] = [word() for _ in range(num_cols)]
|
||||
data[0] = [word() for __ in range(num_cols)]
|
||||
for i in range(1, num_rows):
|
||||
data[i] = [word(), *[number() for i in range(num_cols - 1)]]
|
||||
return data
|
||||
|
||||
|
||||
# ------ Make the Table Data ------
|
||||
data = make_table(num_rows=15, num_cols=6)
|
||||
# sg.set_options(element_padding=(0,0))
|
||||
headings = [data[0][x] for x in range(len(data[0]))]
|
||||
headings = [str(data[0][x]) for x in range(len(data[0]))]
|
||||
|
||||
layout = [[sg.Table(values=data[1:][:], headings=headings, max_col_width=25, background_color='lightblue',
|
||||
# ------ Window Layout ------
|
||||
layout = [[sg.Table(values=data[1:][:], headings=headings, max_col_width=25,
|
||||
# background_color='light blue',
|
||||
auto_size_columns=True,
|
||||
display_row_numbers=True,
|
||||
justification='right',
|
||||
num_rows=20,
|
||||
alternating_row_color='blue',
|
||||
key='-table-',
|
||||
# alternating_row_color='lightyellow',
|
||||
key='-TABLE-',
|
||||
tooltip='This is a table')],
|
||||
[sg.Button('Read'), sg.Button('Double'), sg.Button('Update')],
|
||||
[sg.Text('Read = read which rows are selected')], [sg.Text('Double = double the amount of data in the table')]]
|
||||
[sg.Button('Read'), sg.Button('Double'), sg.Button('Change Colors')],
|
||||
[sg.Text('Read = read which rows are selected')],
|
||||
[sg.Text('Double = double the amount of data in the table')],
|
||||
[sg.Text('Change Colors = Changes the colors of rows 8 and 9')]]
|
||||
|
||||
window = sg.Window('Table', layout, grab_anywhere=False, resizable=True)
|
||||
# ------ Create Window ------
|
||||
window = sg.Window('The Table Element', layout)
|
||||
|
||||
# ------ Event Loop ------
|
||||
while True:
|
||||
event, values = window.read()
|
||||
print(event, values)
|
||||
|
@ -45,9 +53,8 @@ while True:
|
|||
if event == 'Double':
|
||||
for i in range(len(data)):
|
||||
data.append(data[i])
|
||||
window['-table-'].update(values=data)
|
||||
elif event == 'Update':
|
||||
window['-table-'].update(row_colors=((8, 'white',
|
||||
'red'), (9, 'black')))
|
||||
window['-TABLE-'].update(values=data)
|
||||
elif event == 'Change Colors':
|
||||
window['-TABLE-'].update(row_colors=((8, 'white', 'red'), (9, 'green')))
|
||||
|
||||
window.close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue