imLightSpeed
imLightSpeed

Reputation: 157

PySimpleGui Displaying data from a database

PySimpleGui docs don’t explain how to implement the table element. It is unclear if you can assign headers to the table element and how to add rows. Is there a simple example using table that explains the basic functionality?

Upvotes: 1

Views: 5734

Answers (1)

Jason Yang
Jason Yang

Reputation: 13061

There're lot of documents for element Table.

enter image description here

import PySimpleGUI as sg

headings = ['President', 'Date of Birth']

data = [
    ['Ronald Reagan', 'February 6'],
    ['Abraham Lincoln', 'February 12'],
    ['George Washington', 'February 22'],
    ['Andrew Jackson', 'March 15'],
    ['Thomas Jefferson', 'April 13'],
    ['Harry Truman', 'May 8'],
    ['John F. Kennedy', 'May 29'],
    ['George H. W. Bush', 'June 12'],
    ['George W. Bush', 'July 6'],
    ['John Quincy Adams', 'July 11'],
    ['Garrett Walker', 'July 18'],
    ['Bill Clinton', 'August 19'],
    ['Jimmy Carter', 'October 1'],
    ['John Adams', 'October 30'],
    ['Theodore Roosevelt', 'October 27'],
    ['Frank Underwood', 'November 5'],
    ['Woodrow Wilson', 'December 28'],
]

layout = [[sg.Table(data, headings=headings, justification='left', key='-TABLE-')],]
window = sg.Window("Title", layout, finalize=True)

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
    print(event, values)

window.close()

Upvotes: 5

Related Questions