0

I have a PySimpleGui table and I want to select two columns to quickly generate a graph, Is it possible to insert a checkbox in PysimpleGui table headings? Or Is there any other way I can Select both columns?

I have tried to do it by inserting a checkbox in the headings, as expected, i got the TypeError: 'Checkbox' object is not iterable error.

1
  • Please provide enough code so others can better understand or reproduce the problem. Commented Nov 5, 2024 at 9:06

1 Answer 1

1

There's no way to add another element, like the Checkbox, into the PySimpleGUI Table.

Following code demo a way to simulate the action.

import PySimpleGUI as sg

check = "✔"     # ✓✔✅✘❌✖✕❎☓✗
headings = ['President', 'Date of Birth', 'LEN 1', 'LEN 2', 'LEN 3']
data = [
    ['Ronald Reagan', 'February 6'],
    ['Thomas Jefferson', 'April 13'],
    ['George W. Bush', 'July 6'],
    ['John Quincy Adams', 'July 11'],
    ['Jimmy Carter', 'October 1'],
    ['John Adams', 'October 30'],
    ['Frank Underwood', 'November 5'],
    ['Woodrow Wilson', 'December 28'],
]
data = [[name, birthday, str(len(name)), str(len(birthday)), str(len(name+birthday))] for name, birthday in data]
col_widths = list(map(lambda y:max(y)+2, map(lambda x:map(len, x), zip(*([headings] + data)))))

font = ('Courier New', 16, 'bold')
sg.theme('LightPurple')
sg.set_options(font=font)
layout = [
    [sg.Table(
        data, headings=headings, auto_size_columns=False, col_widths=col_widths,
        num_rows=10, cols_justification="llccc", enable_click_events=True,
        key='-TABLE-', metadata=[])],
    [sg.Button('Quit')]
]
window = sg.Window('Checkable Table', layout, finalize=True)
table = window["-TABLE-"]

while True:

    event, values = window.read()

    if event in (sg.WIN_CLOSED, 'Quit'):
        break
    elif isinstance(event, tuple) and event[:2]==('-TABLE-', '+CLICKED+'):
        row, column = event[-1]
        if row == -1:
            if column in table.metadata:
                table.metadata.remove(column)
                table.widget.heading(column, text=headings[column])
            else:
                table.metadata.append(column)
                table.widget.heading(column, text=check+headings[column])

window.close()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.