【发布时间】:2021-07-18 06:35:32
【问题描述】:
我正在使用PySimpleGUI 创建一个文本输出框。
在打开程序时,我希望输出在按下任何按钮之前显示一些默认文本。
我怎样才能让这种情况发生? window.Read() 等待按下按钮。 window.refresh() 似乎不会将文本强制显示在窗口中。
import PySimpleGUI as sg
initialString = "I want this text to display on window opening."
def gui2():
layout = [
[sg.Output(size=(90,20), background_color='black', text_color='white')],
[sg.Button('Do things'), sg.Button('Exit')]
]
window = sg.Window("Funny Title", layout)
#window.read() #I need to press a button before the text will display
#window.refresh() #doesn't refresh the output
print(initialString)
#window.refresh() #doesn't refresh the output
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Exit'):
break
elif event == 'Do things':
print("You pressed the button")
window.close()
gui2()
【问题讨论】:
标签: python user-interface pysimplegui