-1

I’m new in python and trying to create a program which should, among other things, to print a terminal output to a Tkinter GUI.

For example the output of a ping command or any other shell command or a variable print.

I’ve searched the web for a solution but did not find any simple way to do so.

Maybe I’m missing something or there is other way to print the terminal output in python

Thanks in advance,

KC.
  • 2,981
  • 2
  • 12
  • 22
doki.al
  • 21
  • 1
  • 3
  • 1
    Possible duplicate of [How to embed a terminal in a Tkinter application?](https://stackoverflow.com/questions/7253448/how-to-embed-a-terminal-in-a-tkinter-application) – strava Oct 16 '18 at 21:32

1 Answers1

0

You can use subprocess module and Canvas widget to print the result of shell commands to the screen

from tkinter import *
import subprocess


root = Tk()
frame = Frame(root,width=1024, height=768)
frame.grid(row=0, column=0)
c = Canvas(frame, bg='blue', width=800, height=600)
c.config(scrollregion=(0, 0, 800, 3000))
sbar = Scrollbar(frame)
sbar.config(command=c.yview)
c.config(yscrollcommand=sbar.set)
sbar.pack(side=RIGHT, fill=Y)
c.pack(side=LEFT, expand=True, fill=BOTH)

String1 = subprocess.check_output('chcp 437 && ping /?', shell=True)
c.create_text(400, 0, anchor=N, fill='orange', font='Times 15', text=String1)
# c.create_text(750, 300, anchor=W, fill='orange', font='Times 28', text='List')

button = Button(root, text="Quit", command=root.destroy)
c.create_window(400, 0, anchor=N, window=button)

mainloop()
邱俊華
  • 1
  • 1