Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect command line results to a tkinter GUI

Tags:

I have created a program that prints results on command line. (It is server and it prints log on command line.)

Now, I want to see the same result to GUI .

How can I redirect command line results to GUI?

Please, suggest a trick to easily transform console application to simple GUI.

Note that it should work on Linux and Windows.

like image 380
Pratik Deoghare Avatar asked Mar 20 '09 10:03

Pratik Deoghare


People also ask

What does Mainloop () do Tkinter?

mainloop() tells Python to run the Tkinter event loop. This method listens for events, such as button clicks or keypresses, and blocks any code that comes after it from running until you close the window where you called the method.

Does Tkinter block Mainloop?

As far as i know, tkinter mainloop has a blocking effect.

What does get () do in Tkinter?

An Entry widget in Tkinter is nothing but an input widget that accepts single-line user input in a text field. To return the data entered in an Entry widget, we have to use the get() method. It returns the data of the entry widget which further can be printed on the console.

What does root Mainloop () do?

root. mainloop() is a method on the main window which we execute when we want to run our application. This method will loop forever, waiting for events from the user, until the user exits the program – either by closing the window, or by terminating the program with a keyboard interrupt in the console.


1 Answers

You could create a script wrapper that runs your command line program as a sub process, then add the output to something like a text widget.

from tkinter import * import subprocess as sub p = sub.Popen('./script',stdout=sub.PIPE,stderr=sub.PIPE) output, errors = p.communicate()  root = Tk() text = Text(root) text.pack() text.insert(END, output) root.mainloop() 

where script is your program. You can obviously print the errors in a different colour, or something like that.

like image 162
Greg Reynolds Avatar answered Mar 02 '23 01:03

Greg Reynolds