【发布时间】:2019-12-03 15:13:34
【问题描述】:
你们能帮我知道如何在我的 PySimpleGui 脚本中连接一个按钮,当按下/单击运行按钮时,它将执行另一个 python 脚本。
目前,我一直在阅读有关 Subprocess 和 command = os.popen 的 GUI 脚本。
layout = [[ sg.Text('Click the button to launch Program')],
[sg.Button('Launch')]]
win1 = sg.Window('My new window').Layout(layout)
win2_activate = False
while True:
ev1, vals1 = win1.Read()
if ev1 is None or ev1 == 'Cancel':
break
if not win2_activate and ev1 == 'Launch':
win1.Hide()
win2_activate = True
layout2 = [[sg.Text('Report Auto')],
[sg.Input(do_not_clear=True)],
[sg.Text('', key='_OUTPUT_')],
[sg.Button('Run'), sg.Button('Cancel')]]
win2 = sg.Window('Window2').Layout(layout2)
while True:
ev2, vals2 = win2.Read()
if ev2 is None or ev2 =='Cancel':
win2_activate = False
win2.Close()
win1.UnHide()
break
在我的 pysimplegui 脚本中,我还没有包含子进程或任何库,因为我只是不知道在哪里做。欢迎任何帮助!
【问题讨论】:
-
项目的 GitHub 上有几个演示程序,向您展示如何从基于 PySimpleGUI 的程序启动程序。您发布的程序会打开 2 个窗口。您是否要模拟启动程序? Demo_Desktop_Floating_Toolbar.py 使用 subprocess.Popen 启动程序。 Demo_Script_Launcher_Realtime_Output.py 在窗口中显示启动程序的输出。还有另外 5 或 6 个其他示例。
-
非常感谢!在去检查的路上!
-
如果您有任何问题,请随时在该 GitHub 上打开一个问题。
-
发布的答案是否符合您的要求?
-
现在 PySimpleGUI 中还有一个API for executing commands。
标签: python button subprocess command pysimplegui