title: how to change the color of specified word in python
body: <p>How to change the color of selected word in a text file using python?</p>
  
  <p>The below function read from file and match the requested word if its found it change the color of the expression into red.</p>
  
  <p>The problem is that when i run the program the HTML tag  is displayed in the textBox  as text and not as a color  like this.</p>
  
  <pre><code> "&lt;b&gt;&lt;span style='color:white;mso-themecolor:background1;background:black;mso-highlight:black'&gt;"+searchedSTR+"
  </code></pre>
  
  <p>"
  I will appreciate any help with this problem</p>
  
  <h1>code:</h1>
  
  <pre><code>def readFile(self, currentFile):
  
          self.textEdit_PDFpreview.clear()        
          searchedSTR = self.lineEditSearch.text()
          try:
              with open(currentFile) as ctf:
                  ctfRead = ctf.read()               
                  fileName = os.path.basename(currentFile)        
                  RepX = "&lt;b&gt;&lt;span style='color:white;mso-themecolor:background1;background:black;mso-highlight:black'&gt;"+st+"&lt;/span&gt;&lt;/b&gt;"
  
                  thematch=re.sub(searchedSTR,RepX,ctfRead)
                  print("the match \n{}".format(thematch))
                  matches = re.findall(searchedSTR, ctfRead, re.MULTILINE | re.IGNORECASE)                    
                  print(" matches is: \n{}".format(matches))
  
                  if matches:  
                      self.textEdit_PDFpreview.insertHtml(thematch)
                  else:
                      print("Not Found")
                      self.textEdit_PDFpreview.insertHtml(str("no match found"))
  </code></pre>
  
  <h1>functional code :</h1>
  
  <pre><code>import  mainwindow
  
  from PyQt5 import QtCore, QtGui, QtWidgets
  
  
  class appwindow(mainwindow.Ui_MainWindow):
          def __init__(self,winObj:QtWidgets.QMainWindow):
                  self.winObj = winObj
                  self.setupUi(winObj)
                  self.winObj.show()
                  self.pushButton.clicked.connect(self.changeColor)
  
          def changeColor(self):
                  st ="test"
                  x = "&lt;b&gt;&lt;span style='color:white;mso-themecolor:background1;background:black;mso-highlight:black'&gt;"+st+"&lt;/span&gt;&lt;/b&gt;"
  
                  self.textEdit.insertHtml(x)
  
  
  if __name__ == "__main__":
  
          import sys
          app = QtWidgets.QApplication(sys.argv)
          ImainWindow = QtWidgets.QMainWindow()
          ui = appwindow(ImainWindow)
          sys.exit(app.exec_())
  </code></pre>