问题
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