Search code examples
pythonpysimplegui

Table bugging out when combined with expand_x=True


I wrote this code to try to create a column of buttons and a table next to them. However when I set expand_x=True for the table, the columns of the table glitch out as shown in this short video: https://imgur.com/a/1VsRkCL.

Here is my code:

import PySimpleGUI as sg
from PySimpleGUI import *

supporting_table_names: list[str] = [
    "Accounts",
    "Merchants",
    "Locations",
    "Tags",
    "Budgets",
    "Statements",
]

layout: list[list[Element]] = [
    [
        sg.Column(
            list(
                [[sg.Button(name, key=f"-{name}-")] for name in supporting_table_names]
            ),
        ),
        sg.Table(
            values=[
                ["test1", "test1", "test2"],
                ["test2", "test2", "test2"],
                ["test3", "test3", "test3"],
            ],
            headings=["temp", "temp", "temp"],
            expand_x=True,
            auto_size_columns=True,
        ),
    ]
]

window: Window = sg.Window(
    title="Test Program",
    layout=layout,
    size=(1000, 500),
    resizable=True,
)

event, values = window.read()

Why is this happening and how can I set the table to expand in both the x and y directions while not bugging out?


Solution

  • You cannot use same heading in all headings, PySimpleGUI/tkinter will use them as the column ID to identify each column.

    Replace

    headings=["temp", "temp", "temp"],
    

    by

    headings=["temp0", "temp1", "temp2"],