Thiago Pereira Maia
Thiago Pereira Maia

Reputation: 623

PySimpleGUI - Column won't update

Trying to build a simple window with PySimpleGUI. I want to have a list of lines with info about videos that are stored in a list. This is my code:

layout = [
    [sg.Text("Clique para iniciar:")],
    *[[sg.Button(k)] for k in botoes],
    # [sg.Column([[sg.Text('Passos')]], key = 'CONTAINER_STATUS')],
    [sg.Text('Índice Vídeo Selecionado:'), sg.In(key=0), sg.In(key=1, enable_events=True)],
    # [sg.Text('Status Vídeos: ')],
    [sg.Text('Vídeo'), sg.Text('Status Vídeo'), sg.Text('Status Thumbnail')],
    [sg.Column([[sg.Text('test'), sg.Text('test2')],[sg.Text('test3'),sg.Text('test4')]], key='CONTAINER_VIDEOS', size= (50, 50))],
]

window = sg.Window("Iniciar Processamento de Vídeo", layout)

def get_layout_video(video):
    status = video.status.name if video.status is not None else ''
    status_thumb = video.thumbnail.status.name if video.thumbnail.status is not None else ''
    try:
        layout = [
            sg.Text(video.id_video_original), sg.Text(status), sg.Text(status_thumb)
        ]
        return layout
    except Exception as e:
        print(e)
        return []

# Create an event loop
print('Running')
while True:
    event, values = window.read()

    window["CONTAINER_VIDEOS"].update([get_layout_video(v) for v in sessao.videos] if len(sessao.videos) > 0 else [[]])
    if event == sg.WIN_CLOSED:
        break

I have debugged with several different possibilities. The events that cause the list to change were omitted, but I'm sure they work. The result of get_layout_video is correct, it looks like a normal layout for the column, similar to the test one. I have also tried an empty list of lists [[]], but nothing happens. The Column simply keeps it's original value. When I try another type of element (such as sg.Text) it works correctly, updating the value. What am I doing wrong?

Upvotes: 1

Views: 2161

Answers (1)

Kfir Ram
Kfir Ram

Reputation: 334

I couldn't find how to directly change the column of the sg, but I made an update function that will solve your problem, it will close and recreate the sg window with the updated column.

Here is the code for the update column.

def update_column():
global window
layout = [
    [sg.Text("Clique para iniciar:")],
    *[[sg.Button(k)] for k in botoes],
    # [sg.Column([[sg.Text('Passos')]], key = 'CONTAINER_STATUS')],
    [sg.Text('Índice Vídeo Selecionado:'), sg.In(key=0), sg.In(key=1, enable_events=True)],
    # [sg.Text('Status Vídeos: ')],
    [sg.Text('Vídeo'), sg.Text('Status Vídeo'), sg.Text('Status Thumbnail')],
    [sg.Column([get_layout_video(v) for v in sessao.videos] if len(sessao.videos) > 0 else [[]], key='CONTAINER_VIDEOS', size=(150, 50))],
]
window.close()
window = sg.Window("Iniciar Processamento de Vídeo", layout)

print('Running')
while True:
    event, values = window.read()
    update_column()
    if event == sg.WIN_CLOSED:
        break

some photos:

before I click anything:

after I click something:

Upvotes: 2

Related Questions