How add text without new line in QTextEdit PyQt4 Python 2.7?

4.9k views Asked by At

I have problem with add text without new line in QTextEdit. I must add the value of variable "self.value" and next text ", word" It's my code:

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Text(QWidget):
   def __init__(self, parent = None):
      super(Text, self).__init__(parent)

      self.value = 5

      layout = QHBoxLayout()
      self.text_edit = QTextEdit()
      self.text_edit.append(str(self.value))
      self.text_edit.append(",   word")
      layout.addWidget(self.text_edit)
      self.setLayout(layout)
      self.setWindowTitle("TextEdit")

def main():
   app = QApplication(sys.argv)
   ex = Text()
   ex.show()
   sys.exit(app.exec_())

if __name__ == '__main__':
   main()

And I get:

5
,   word

But I would like:

5,   word

Help me, please

1

There are 1 answers

0
PYPL On

Easily like this

  self.text_edit = QTextEdit()
  self.text_edit.insertPlainText(str(self.value))
  self.text_edit.insertPlainText(",   word")