stdout to tkinter GUI

0 votes
I want to redirect stdout data to a tkinter Text widget. Can anyone tell me on how to do this?
Apr 10, 2019 in Python by ana1504.k
• 7,890 points

1 answer to this question.

0 votes
You need to make a file-like class whose write method writes to the Tkinter widget instead, and then do sys.stdout = <your new class>.

For example:

class IORedirector(object):
    '''A general class for redirecting I/O to this Text widget.'''
    def __init__(self,text_area):
        self.text_area = text_area

class StdoutRedirector(IORedirector):
    '''A class for redirecting stdout to this Text widget.'''
    def write(self,str):

and then, in your Tkinter widget:

# To start redirecting stdout:
import sys
sys.stdout = StdoutRedirector( self )
# (where self refers to the widget)

# To stop redirecting stdout:
sys.stdout = sys.__stdout__
answered Apr 10, 2019 by SDeb
• 13,250 points

Related Questions In Python

0 votes
1 answer
+1 vote
1 answer

How to use GUI that comes with Python to test your code?

Hey @alex0809, When your testing a website ...READ MORE

answered Sep 24, 2018 in Python by Vardhan
• 13,200 points
0 votes
1 answer

How to invoke method on GUI thread but without have that method in QMainWindow class (Pyqt)

It is possible to handle this by ...READ MORE

answered Sep 24, 2018 in Python by Priyaj
• 57,530 points
0 votes
1 answer

How to I clear Tkinter Canvas using Python?

To clear a canvas, use the delete method.  This ensures ...READ MORE

answered Dec 24, 2018 in Python by Nymeria
• 3,540 points
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,101 views
0 votes
0 answers
0 votes
1 answer

Tkinter to android translation

Even for native purposes, most developers would ...READ MORE

answered May 22, 2019 in Python by SDeb
• 13,250 points
0 votes
1 answer

How to convert string into epoch time?

you are passing the parsed datetime object to ...READ MORE

answered Sep 21, 2018 in Python by SDeb
• 13,250 points