Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6908065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:30:52+00:00 2026-05-27T08:30:52+00:00

I have a program in Python with PyQt, designed to run on Windows. This

  • 0

I have a program in Python with PyQt, designed to run on Windows.
This program makes a lot of operations and prints a lot of info.
But as I want to freeze it and don’t want the prompt screen to appear, I want that all that info appears in the main application, in a QTextEdit or so.
How can i make the program work so it gets the output from the interpreter and shows it on the textEdit at the same time, just like it does on the real interpreter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:30:53+00:00Added an answer on May 27, 2026 at 8:30 am

    I assume that with “output from the interpreter”, you mean output written to the console or terminal window, such as output produced with print().

    All console output produced by Python gets written to the program’s output streams sys.stdout (normal output) and sys.stderr (error output, such as exception tracebacks). These are file-like objects.

    You can replace these streams with your own file-like object. All your custom implementation must provide is a write(text) function. By providing your own implementation, you can forward all output to your widget:

    class MyStream(object):
        def write(self, text):
            # Add text to a QTextEdit...
    
    sys.stdout = MyStream()
    sys.stderr = MyStream()
    

    If you ever need to reset these streams, they are still available as sys.__stdout__ and sys.__stderr__:

    sys.stdout = sys.__stdout__
    sys.stderr = sys.__stderr__
    

    Update

    Here is some working code for PyQt4. First define a stream that reports data written to it with a Qt signal:

    from PyQt4 import QtCore
    
    class EmittingStream(QtCore.QObject):
    
        textWritten = QtCore.pyqtSignal(str)
    
        def write(self, text):
            self.textWritten.emit(str(text))
    

    Now, in your GUI, install an instance of this stream to sys.stdout and connect the textWritten signal to a slot that writes the text to a QTextEdit:

    # Within your main window class...
    
    def __init__(self, parent=None, **kwargs):
        # ...
    
        # Install the custom output stream
        sys.stdout = EmittingStream(textWritten=self.normalOutputWritten)
    
    def __del__(self):
        # Restore sys.stdout
        sys.stdout = sys.__stdout__
    
    def normalOutputWritten(self, text):
        """Append text to the QTextEdit."""
        # Maybe QTextEdit.append() works as well, but this is how I do it:
        cursor = self.textEdit.textCursor()
        cursor.movePosition(QtGui.QTextCursor.End)
        cursor.insertText(text)
        self.textEdit.setTextCursor(cursor)
        self.textEdit.ensureCursorVisible()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python program (with Django - does this matter?) that I want
I have a python program/file that I want to run repeatedly and calculate the
I have a program that is run from the command line like this python
I have a python program that is going to eat a lot of memory,
I have a python program that has no windows frame and doesn't show up
I have a PyQt program used to visualize some python objects. I would like
I have a python program that does something like this: Read a row from
I have a Python program for Linux almost looks like this one : import
I have a Python program I am writing and I want it to be
I have a Python program that works with dictionaries a lot. I have to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.