I wanted to try out some GUI stuff in Python. Im new to both Python and PySimpleGUI. I decided to make a program that when given an IP address would ping it and show the reply in a popup. (super simple i know.)
It works perfectly, however: It is showing the response in the console, but I want it in the GUI.
Is it possible to save the console output in a variable and that way show it in the GUI?
I hope the question makes sense :)
This is my code:
#1 Import:
import PySimpleGUI as sg
import os
#2 Layout:
layout = [[sg.Text('Write the IP-address you want to ping:')],
[sg.Input(key='-INPUT-')],
[sg.Button('OK', bind_return_key=True), sg.Button('Cancel')]]
#3 Window:
window = sg.Window('Windows title', layout)
#4 Event loop:
while True:
event, values = window.read()
os.system('ping -n 1 {}'.format(values['-INPUT-']))
if event in (None, 'Cancel'):
break
#5 Close the window:
window.close()