简体   繁体   English

PySimpleGUI:如何在我的 window 中显示结果?

[英]PySimpleGUI: How can I display a result in my window?

How can I display a result in a window?如何在 window 中显示结果? I'm using PySimpleGUI to make user interface and I'm trying to display the result in the window. I was using sg.Output() but I didn't like the look.我正在使用 PySimpleGUI 制作用户界面,并试图在 window 中显示结果。我正在使用sg.Output()但我不喜欢它的外观。

import PySimpleGUI as sg

layout = [
         [sg.Text("Name: "), sg.Input()],
         [sg.Ok()]
]

window = sg.Window("Just a window", layout)

while True:
    events, values = window.read()
    name = values[0]

Now, how can I display the name in the window as a text?现在,如何将 window 中的名称显示为文本? I don't want to use sg.Output() .我不想使用sg.Output()

You can use sg.Text as the output of the result, set option size of sg.Text to (maximum, 1) , like (40, 1) , or (0, 1) .您可以使用sg.Text作为结果的 output,将sg.Text的选项size设置为(maximum, 1) ,例如(40, 1)(0, 1)

import PySimpleGUI as sg

layout = [
    [sg.Text("Name: "), sg.Input(key='INPUT')],
    [sg.Ok()],
    [sg.Text("", size=(0, 1), key='OUTPUT')]
]

window = sg.Window("Just a window", layout)

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
    elif event == 'Ok':
        name = values['INPUT']
        window['OUTPUT'].update(value=name)

window.close()

Just use a text box:只需使用一个文本框:

import PySimpleGUI as sg

output = sg.Text()
layout = [
         [sg.Text("Name: "), sg.Input()],
         [output],
         [sg.Ok()]
]

window = sg.Window("Just a window", layout)

while True:
    events, values = window.read()
    name = values[0]
    output.update(value=name)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM