Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading