title: How can I use a QTextBrowser instead of the console in Python?
body: <p>I've constructed a window in PyQt 5, which by clicking on the &quot;optimize&quot; button, the program reads the &quot;Gurobi-model.lp&quot; file <a href="https://drive.google.com/file/d/1V9c-HlSap8h4gVq_SCa7PBb6AWvxjnxO/view" rel="nofollow noreferrer">(click here to get the file)</a>, and optimizes it by the help of the Gurobi software. How can I display the logs of the Gurobi on a QTextBrowser?</p>
  <p>I found some functions in the Gurobi such as OutputFlag, LogFile, and LogToConsole. Might these functions be helpful not?</p>
  <p>For those who are not familiar with Gurobi, the Gurobi optimizer uses Python as an interface, and produces some logs that allows you to track the progress of the optimization. These logs are printed in the console during the optimization, and somehow, responding my question doesn't need to know anything about the Gurobi.</p>
  <p>In the below code, I've found a way to show the logs in the QTextBrowser, but the logs are represented when the optimization process is completely done. I want the logs to be represented exactly during the optimization process.</p>
  <pre><code>import sys
  from PyQt5.QtWidgets import *
  from gurobipy import *
  from io import *
  
  
  class MyWindow(QWidget):
  
      def __init__(self):
          QWidget.__init__(self)
  
          self.pb = QPushButton(self.tr(&quot;optimize&quot;))
          self.log_text = QTextBrowser()
  
          layout = QVBoxLayout(self)
          layout.addWidget(self.pb)
          layout.addWidget(self.log_text)
          self.setLayout(layout)
  
          self.pb.clicked.connect(self.optimize)
  
       def optimize(self):
  
          f = StringIO()
          sys.stdout = StringIO()
  
          self.m = read('Gurobi-model.lp')
          self.m.optimize()
          self.log_text.append(sys.stdout.getvalue() )
  
  
  def main():
     app = QApplication(sys.argv)
     w = MyWindow()
     w.show()
     sys.exit(app.exec_())
  
  if __name__ == &quot;__main__&quot;:
      main()
  </code></pre>