PySimpleGUI/DemoPrograms/Demo_Script_Launcher_Realti...

32 lines
1.0 KiB
Python
Raw Normal View History

2019-04-26 15:32:21 +00:00
import PySimpleGUI as sg
"""
Demo Program - Realtime output of a shell command in the window
Shows how you can run a long-running subprocess and have the output
be displayed in realtime in the window.
Copyright 2022 PySimpleGUI
2019-04-26 15:32:21 +00:00
"""
2019-12-24 23:52:47 +00:00
2019-04-26 15:32:21 +00:00
def main():
layout = [
[sg.Multiline(size=(110, 30), echo_stdout_stderr=True, reroute_stdout=True, autoscroll=True, background_color='black', text_color='white', key='-MLINE-')],
[sg.T('Promt> '), sg.Input(key='-IN-', focus=True, do_not_clear=False)],
[sg.Button('Run', bind_return_key=True), sg.Button('Exit')]]
window = sg.Window('Realtime Shell Command Output', layout)
while True: # Event Loop
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Exit'):
break
elif event == 'Run':
sp = sg.execute_command_subprocess(values['-IN-'], pipe_output=True, wait=False)
results = sg.execute_get_results(sp, timeout=1)
print(results[0])
window.close()
2019-04-26 15:32:21 +00:00
main()