如何使用 PYSIMPLEGUI 在文本小部件中显示函数的输出?
How to display the output from a function in a text wdiget with PYSIMPLEGUI?
如何在弹出文本输出中显示函数的结果?
import PySimpleGUI as sg
FILMS = [["There will be blood", "Paul Thomas Anderson", 2007],
["Lion King","Rob Minkoff", 1994],
["Toy Story","Josh Cooley",1995],
["Monty Python's Life of Brian","Terry Jones",1979],
["Die Hard","John McTiernan",1988],
["Rocky","John G. Avildsen",1976]]
def listprint():
for i in range (len(FILMS)):
print(FILMS[i][0])
event, values = sg.Window('Find a film', [[sg.Text('Are you ready:')],[sg.B("OK",key="-OK-"), sg.B("Return",key="-Return-")] ]).read(close=True)
if event == '-OK-':
sg.popup('Film names will be printed in the python output:',command = listprint)
只是将结果传递给sg.popup
,但使用*
解压list/tuple。有时,它看起来不太好,您可以使用用户定义的弹出窗口 window 来显示它们。
import PySimpleGUI as sg
def film_name():
return [item[0] for item in FILMS]
FILMS = [
["There will be blood", "Paul Thomas Anderson", 2007],
["Lion King","Rob Minkoff", 1994],
["Toy Story","Josh Cooley",1995],
["Monty Python's Life of Brian","Terry Jones",1979],
["Die Hard","John McTiernan",1988],
["Rocky","John G. Avildsen",1976],
]
layout = [
[sg.Text('Are you ready:')],
[sg.B("OK"), sg.B("Return")],
]
window = sg.Window('Find a film', layout, finalize=True)
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, 'Return'):
break
elif event == 'OK':
sg.popup('Film names will be printed in the python output:', *film_name())
print(event, values)
window.close()
如何在弹出文本输出中显示函数的结果?
import PySimpleGUI as sg
FILMS = [["There will be blood", "Paul Thomas Anderson", 2007],
["Lion King","Rob Minkoff", 1994],
["Toy Story","Josh Cooley",1995],
["Monty Python's Life of Brian","Terry Jones",1979],
["Die Hard","John McTiernan",1988],
["Rocky","John G. Avildsen",1976]]
def listprint():
for i in range (len(FILMS)):
print(FILMS[i][0])
event, values = sg.Window('Find a film', [[sg.Text('Are you ready:')],[sg.B("OK",key="-OK-"), sg.B("Return",key="-Return-")] ]).read(close=True)
if event == '-OK-':
sg.popup('Film names will be printed in the python output:',command = listprint)
只是将结果传递给sg.popup
,但使用*
解压list/tuple。有时,它看起来不太好,您可以使用用户定义的弹出窗口 window 来显示它们。
import PySimpleGUI as sg
def film_name():
return [item[0] for item in FILMS]
FILMS = [
["There will be blood", "Paul Thomas Anderson", 2007],
["Lion King","Rob Minkoff", 1994],
["Toy Story","Josh Cooley",1995],
["Monty Python's Life of Brian","Terry Jones",1979],
["Die Hard","John McTiernan",1988],
["Rocky","John G. Avildsen",1976],
]
layout = [
[sg.Text('Are you ready:')],
[sg.B("OK"), sg.B("Return")],
]
window = sg.Window('Find a film', layout, finalize=True)
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, 'Return'):
break
elif event == 'OK':
sg.popup('Film names will be printed in the python output:', *film_name())
print(event, values)
window.close()