如何在同一个 window 中打印选定的 Table 元素?

How to print selected Table Element within the same window?

我正在研究 simple executable,它允许我 select 一个 table 元素。

目前,当我 select 一个 table 元素时,它会生成一个 popup notifying 我已经 select 编辑了特定元素

但是,每次我 select 一个元素时,我都希望 print the element 在 table 旁边的大空白 space 中输出,但是我找到的解决方案没有完全符合我的想法。我的困境有解决办法吗?

import PySimpleGUI as sg

choices = ('Windows Enterprise 10','Windows Server 19','MacOS','Ubuntu','Debian')

layout = [  [sg.Text('Pick an OS')],
            [sg.Listbox(choices, size=(20, 5), key='-OS-', enable_events=True)] ]

window = sg.Window('Pick an OS', layout,size=(500,200))

while True:                  # the event loop
    event, values = window.read()
    if event == sg.WIN_CLOSED:
        break
    if values['-OS-']:    # if something is highlighted in the list
        sg.popup(f"The OS you selected is: {values['-OS-'][0]}")
window.close()

sg.Listbox 旁边放置另一个元素来显示结果,然后用 sg.Listbox 的值更新该元素。元素可以是 sg.Text 需要自己将消息拆分成行,或者 sg.Multiline.

import PySimpleGUI as sg

choices = (
    'Windows Enterprise 10',
    'Windows Server 19',
    'MacOS',
    'Ubuntu',
    'Debian',
)

sg.theme('DarkBlue3')
sg.set_options(font=("Courier New", 12))

layout = [
    [sg.Text('Pick an OS')],
    [sg.Listbox(choices, size=(22, 5), key='-OS-', enable_events=True),
     sg.Text('', size=(40, 2), font=("Courier New", 12, 'bold'), key='-OUTPUT-')],
]

window = sg.Window('Pick an OS', layout)

while True:                  # the event loop
    event, values = window.read()
    if event == sg.WIN_CLOSED:
        break
    elif event == '-OS-':
        text = f"You have selected: {values['-OS-'][0]}\nOperating System"
        window['-OUTPUT-'].update(value=text)

window.close()
import PySimpleGUI as sg

choices = ('Windows Enterprise 10','Windows Server 19','MacOS','Ubuntu','Debian')
layout = [[sg.Text('Pick an OS')],
            [sg.Listbox(choices, size=(20, 5), key='-OS-', enable_events=True), 
            sg.Text(key='OUT', size=(30,5), text_color='#000000',background_color='#ffffff')]]

window = sg.Window('Pick an OS', layout,size=(500,200))

while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED:
        break
    else:
        choice = values['-OS-']
        window['OUT'].update(f'You have selected:\n{choice}')
window.close()