Python – PySimpleGUI. How to make a scroll in sg.Column?

I have sg.Column whit enabled options "scrollable" and "vertical_scroll_only". I add new elements to it using extend_layout. When there are a lot of elements, the scroll is not activated.

I used this article – How to add a field or element by clicking a button in PySimpleGUI?

How can I fix it?

import PySimpleGUI as sg

new_layout = [[sg.T(f'Row 1'), sg.B(' + ', key='-ADD-')]]

layout = [[sg.T('Example Text')],
        [sg.Column(new_layout, key='-Column-', size=(100, 200),
        scrollable=True, vertical_scroll_only=True)]]

window = sg.Window('For Example', layout)

def new_row(row_amt):
    return [[sg.T(f'Row {row_amt}')]]

row_amt = 2
while True:
    event, values = window.read()
    if event in (sg.WIN_CLOSED, None):
        break
    elif event == '-ADD-':
        window.extend_layout(window['-Column-'], new_row(row_amt))
        row_amt += 1

>Solution :

You can call the method column.contents_changed if the content of a scrollable Column changed. Remember to call window.refresh() before you call it.

When a scrollable column has part of its layout changed by making elements visible or invisible or the layout is extended for the Column, then this method needs to be called so that the new scroll area
is computed to match the new contents.

Leave a Reply