So here I made a very simple version of what You may want (type in python --version
to try out):
from tkinter import Tk, Text
import subprocess
def run(event):
command = cmd.get('1.0', 'end').split('
')[-2]
if command == 'exit':
exit()
cmd.insert('end', f'
{subprocess.getoutput(command)}')
root = Tk()
cmd = Text(root)
cmd.pack()
cmd.bind('<Return>', run)
root.mainloop()
the subprocess.getoutput()
gets the output the cmd would give if the given command was used
EDIT (moved comment here):
there are some limitations however for example running pause will just crash tkinter and the output will be given only after command has finished running for example if You tracert google.com
it may take a while and during that the window will be unresponsive until it completes the process and then puts it all out (maybe for that it is possible to use threads to not make the window unresponsive at least)
EDIT (28.07.2021.):
Probably better to use subprocess.Popen
and stream data from there
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…