Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to redirect sys.stdout to two or more separate widgets?

$
0
0
class EmitStr(QObject):    update_info_signal = pyqtSignal(str)    def write(self, text):        self.update_info_signal.emit(str(text))        QApplication.processEvents()sys.stdout = EmitStr()sys.stdout.update_info_signal.connect(self.update_info)

I use this class to redirect stdout to textBroswer in a window. It works, but when I open the second window, some problems come. For example, I have two windows, each of them have a textBroswer widget; I want these two windows run task separately by using QThread, like print 1 to 10, but all numbers printed will be displayed on the window opened later. How to solve this problem?

I want to solve this problem without by using module logging, don't change print() in other .py files and other functions. I think sys.stdout is single; if I redirect sys.stdout to one window's textBrowser, it works, but when the second window opened, sys.stdout will be redirected to the second window and all the prints will be displayed on the second window. Here are two screenshots.

open two windows before running

open the second window when the first window is running


Viewing all articles
Browse latest Browse all 23131

Trending Articles