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 in Python by ana1504.k
• 5,990 points
47 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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):
        self.text_area.write(str,False)
 

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 by SDeb
• 9,540 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
• 10,570 points
30 views
0 votes
1 answer
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,500 points
700 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
20 views
0 votes
1 answer

Tkinter to android translation

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

answered 9 hours ago in Python by SDeb
• 9,540 points
4 views
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
• 9,540 points
46 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.