how to manage scrollbar with not visible items in PySimpleGUI

Question:

i have developed a PySimpleGUI application and i must show a list of items depending from the number of rows readed from a file.
I know that is not possible to create components dinamically in PySimpleGUI, so i’ve defined a max number of components and set they as not visible until the file is readed.

After the reading, i set the desired number of rows as visible, but the scrollbar of the Column container remains unusable.

Initial situation:
enter image description here

After the reading:
enter image description here

I also try to leave an item of the row always visibile, and in this case scrollbar works well:

Initial situation with index always visible:
enter image description here

After the reading with index always visible:
enter image description here

Code:

def getLayoutFramePars():
    sub_layout = []

    for node_index in range(30):
        line = addParLine(node_index)
        sub_layout.append(line)

    layout = [
        [
            sg.Col(
                layout=sub_layout,
                background_color=Blue4,
                expand_x=True,
                expand_y=True,
            )
        ]
    ]

    return layout


def addParLine(index):
    text_index = str(index)

    if index < 10:
        text_index = "0" + text_index

    KEY_LABEL_INDEX = PREFIX_PAR_LABEL_INDEX + text_index
    KEY_LABEL_NAME = PREFIX_PAR_LABEL_NAME + text_index
    KEY_LABEL_VALUE = PREFIX_PAR_LABEL_VALUE + text_index
    KEY_BUTTON_READ = PREFIX_PAR_BUTTON_READ_VALUE + text_index
    KEY_BUTTON_SEND = PREFIX_PAR_BUTTON_SEND_VALUE + text_index

    layout = [
        sg.Text(
            key=KEY_LABEL_INDEX,
            text=text_index,
            size=LABEL_SIZE_05,
            justification=ALIGN_CENTER,
            visible=False,
            pad=5,
        ),

        sg.Text(
            '',
            key=KEY_LABEL_NAME,
            size=LABEL_SIZE_20,
            relief=sg.RELIEF_SUNKEN,
            justification=ALIGN_CENTER,
            visible=False,
            pad=5,
        ),

        sg.InputText(
            '',
            key=KEY_LABEL_VALUE,
            size=LABEL_SIZE_30,
            justification=ALIGN_LEFT,
            text_color=Blue2,
            background_color=LightGrey,
            enable_events=True,
            visible=False,
            pad=5,
        ),

        sg.Button(
            key=KEY_BUTTON_READ,
            button_text='Leggi',
            size=BUTTON_SIZE_14,
            button_color=BUTTON_COLOR_BLUE,
            visible=False,
            pad=5,
        ),

        sg.Button(
            key=KEY_BUTTON_SEND,
            button_text='Invia',
            size=BUTTON_SIZE_14,
            button_color=BUTTON_COLOR_BLUE,
            visible=False,
            pad=5,
        ),
    ]

    return layout


def initLayoutBody():
    layout = [
        [
            sg.Text(
                text="##",
                size=LABEL_SIZE_05,
                text_color=DarkOrange,
                justification=ALIGN_CENTER,
                pad=5,
            ),

            sg.Text(
                text="Nome",
                size=LABEL_SIZE_20,
                text_color=DarkOrange,
                justification=ALIGN_CENTER,
                pad=5,
            ),

            sg.Text(
                text="Valore",
                size=LABEL_SIZE_30,
                text_color=DarkOrange,
                justification=ALIGN_CENTER,
                pad=5,
            ),
        ],
        [
            sg.Column(
                key=KEY_FRAME_PARS,
                size=(750, 300),
                layout=getLayoutFramePars(),
                element_justification=ALIGN_LEFT,
                scrollable=True,
                vertical_scroll_only=True,
                background_color=DarkGreen,
            ),
        ]
    ]

    return layout

Could someone help me to understand what i do wrong and how to solve this problem?

Thanks

Asked By: Tirrel

||

Answers:

Call following methods after you update the content of the column.

  • window.refresh() to update the GUI.
  • window[column_key].contents_changed() to update the new scroll area
    to match the new contents.
Answered By: Jason Yang