Display console results to a PyQt5 text box [duplicate]

老子叫甜甜 提交于 2021-02-16 15:41:05

问题


I am trying to create a graphical interface where my results of certain processes of my program are shown on the screen to a text box, to view them from there.

For this I have created a QtextBrowser, the problem is that when loading the results to that widget, nothing appears, a 'NONE' message appears.

The function that prints on screen is called 'calculu', I attach the respective .ui files in the folder. ui FILES

import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.uic import loadUi

import numpy as np

# CLASS WINDOW PRINCIPAL
# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
class mainWindowInicial(QMainWindow):
    def __init__(self, parent=None):
        super(mainWindowInicial,self).__init__(parent)
        loadUi('Gui/principal_main.ui', self)
        self.actionInputs.triggered.connect(self.open_dataInput)      
        self.actionOuputs.triggered.connect(self.open_result)         

    # EVENTS ==================================================================
    def open_dataInput(self):
        DataInput(self).show()
        
    def open_result(self):
        Result(self).show()
        

def calculu():
    
    print('THIS IS SOME EXAMPLE ....')
    print('Many, many calculus ....')
    print('Many, many calculus ....')
    print('Many, many calculus ....')
    
    print('Hello World')
    print('Hello')
    print('World')
    
    x = np.array([0,0,0])
    
    print(x)
    
    print('.................')


class DataInput(QMainWindow):

    def __init__(self, parent=None):
        super(DataInput,self).__init__(parent)
        loadUi('Gui/window_principal.ui', self)

        self.parent = parent        

        # BUTTONS ============================================
        self.pushButton.clicked.connect(self.analisisdisenio)  

    # EVENTS ======================================================

    def analisisdisenio(self):
        
        self.details = calculu()
        self.parent.details = self.details        
        

class Result(QMainWindow):

    def __init__(self, parent=None):
        super(Result,self).__init__(parent)
        loadUi('Gui/window_second.ui', self)

        self.parent = parent 

        # OUTPUTS
        self.show_details = self.parent.details
        
        # CONNECT WIDGETS
        self.textBrowser.setText('''<b>I DIRECT THE CONSOLE DEPARTURES HERE, 
                                 MY GOAL IS TO VIEW CONSOLE RESULTS BUT FROM 
                                 MY TEXT BROWSER.:</b>\n''')
        self.textBrowser.append(str(self.show_details))        
        
if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = mainWindowInicial()
    widget.show()
    sys.exit(app.exec_())

来源:https://stackoverflow.com/questions/63240599/display-console-results-to-a-pyqt5-text-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!