PySimpleGui - 可以改变每行 sg.Output 的字体

PySimpleGui - Possible to alter font per line of sg.Output

我有一个用于 'chat' 应用程序的简单 PySimpleGui 屏幕。我希望能够通过更改用于打印的每一行的字体(理想颜色)来区分人们的消息...我只是使用 print('message') 输出但想知道我是否可以添加类似 [=13 的东西=] 或类似的东西...这样我就可以加粗我自己的信息,并让其他人用不同的颜色进来。

聊天window代码就是这样:

chatWindow = [[sg.Output(size=(90, 37), font=('Helvetica 10'))],
                [sg.Multiline(size=(75, 5), enter_submits=False, key='-QUERY-', do_not_clear=False),
                sg.Button('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True),
                sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]]

关闭。它不是 color=red,而是 text_color='red',如 print(1,2,3,4,end='', text_color='red', background_color='yellow')

查看相应的 Cookbook 食谱 - Recipe Printing - #3/4 Print to Multiline Element

为方便起见,此处转载代码:

import PySimpleGUI as sg

layout = [  [sg.Text('Demonstration of Multiline Element Printing')],
            [sg.MLine(key='-ML1-'+sg.WRITE_ONLY_KEY, size=(40,8))],
            [sg.MLine(key='-ML2-'+sg.WRITE_ONLY_KEY,  size=(40,8))],
            [sg.Button('Go'), sg.Button('Exit')]]

window = sg.Window('Window Title', layout, finalize=True)


# Note, need to finalize the window above if want to do these prior to calling window.read()
window['-ML1-'+sg.WRITE_ONLY_KEY].print(1,2,3,4,end='', text_color='red', background_color='yellow')
window['-ML1-'+sg.WRITE_ONLY_KEY].print('\n', end='')
window['-ML1-'+sg.WRITE_ONLY_KEY].print(1,2,3,4,text_color='white', background_color='green')
counter = 0

while True:             # Event Loop
    event, values = window.read(timeout=100)
    if event in (sg.WIN_CLOSED, 'Exit'):
        break
    if event == 'Go':
        window['-ML1-'+sg.WRITE_ONLY_KEY].print(event, values, text_color='red')
    window['-ML2-'+sg.WRITE_ONLY_KEY].print(counter)
    counter += 1
window.close()

看到编辑框中的文本如何从红色变为白色再变为红色了吗?