0

How to find an element inside a PySimpleGui's Frame by a key without hardcoding it via .Rows[0]?

import PySimpleGUI as sg

layout = [
    [sg.Frame(layout=[
        [sg.Text('Field:'), sg.Text('', key='key')],
    ])]
]

window = sg.Window("Name", layout)

1 Answers1

0

You can use window['-KEY NAME-'] to find an element by it's key. Here is an example:

import PySimpleGUI as sg

layout = [
    [sg.Frame(title='My Frame', layout=[
        [sg.Text('Field:'), sg.Text('', key='-KEY NAME-', size=(10, 0))]])],
    [sg.Button('Go')] 
]

window = sg.Window(title='Name', layout=layout).finalize()

window['-KEY NAME-'].update('No value set')

# MAIN LOOP
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED:
        break
    if event == 'Go':
        window['-KEY NAME-'].update('Hello World!')

window.close()

Joe
  • 80
  • 2
  • 10