如何在多行 PySimpleGUI 元素中打印多行 words/phrases?

How can I print more than one line of words/phrases in a Multiline PySimpleGUI element?

下面的小程序创建了一个 window,其中包含一个 Multiline 元素、一个 Input 元素和一个按钮。当我在输入字段中键入单词或短语时,word/phrase 也会打印在多行元素内。但是当我输入第二个 word/phrase 时,第一个被多行中的第二个替换。如何在 Multiline 元素中将其中的两个或多个保持在另一个下方(多行)? 这是代码:

import PySimpleGUI as sg

sz = (7,1)

column1 = [ [sg.ReadButton('UPDATE\nTEXT', size=sz)],
            [sg.ReadButton('LOAD-\nTEXT', size=sz)],
            [sg.ReadButton('SAVE-VOC', size=sz)],
            [sg.ReadButton('CLEAR\nTEXT', size=sz)]
            ]

column2 = [[sg.ReadButton('Click here')]]

col_layout = [
                [sg.InputText(focus=True, key='word')],
                [sg.Column(column2)]
             ]

layout = [
            [sg.Text("Study Text Box")],
            [sg.Multiline(size=(50,10), font='Tahoma 13', key='-STLINE-', autoscroll=True), sg.Column(column1), sg.VerticalSeparator(pad=None), sg.Column(col_layout)]
         ]
        

window = sg.Window("TbLLT Program", layout, resizable=True, finalize=True)

while True:
    event, values=window.read()
    if event == sg.WIN_CLOSED or event == 'Exit':
        break
    if event == 'SAVE-VOC':
        with open('someText(saved).txt', 'w+') as file:
            savedText1 = file.write(values['-STLINE-'])
        file.close()
    if event == 'Click here':
        window['-STLINE-'].update(values['word'])
window.close()

使用方法update会替换sg.Multiline的全部内容,或者多一个选项append=True,但需要的时候需要自己添加'\n'

使用 sg.Multiline 的方法 print 像 Python 一样正常打印,除了将输出路由到多行元素并根据需要添加颜色。

def print(self, *args, end=None, sep=None, text_color=None,
    background_color=None, justification=None, font=None, colors=None, t=None,
    b=None, c=None,  autoscroll=True):

这样称呼它

        window['-STLINE-'].print(values['word'])

或使用选项 append=True 调用方法 update

        window['-STLINE-'].update(values['word']+'\n', append=True)