0

I'm newbie on PyQt5. I just wonder why print method doesn't print whitespace characters when it is connected to QLineEdit's signal

For example:

print("Hello\tWorld\n")

should print the following:

Hello   World

But when I run the following code

class window(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.setLayout(QVBoxLayout())
        self.lineedit = QLineEdit()
        self.layout().addWidget(self.lineedit)
        self.lineedit.textChanged.connect(print)
        self.show()

app = QApplication(sys.argv)
mw = window()
sys.exit(app.exec())

And when I past the same things in the previous code: Hello\tWorld\n , the result is

Hello\tWorld\n

I just wonder what it happens to print method that it doesn't print any whitespace character?

Note: My OS is MacOs Catalina

  • "\n" is just one character in the print function, instead in QLineEdit you put 2 characters: "\" and "n" (the same for "\t") so they are not the same. – eyllanesc Jun 07 '21 at 16:51
  • You can see the difference if you check the bytes of the string: `text = "Hello\tWorld\n"` `print(text.encode())` and `self.lineedit.textChanged.connect(lambda text: print(text.encode()))`, outputs: `b'Hello\tWorld\n'` and `b'Hello\\tWorld\\n'`. – eyllanesc Jun 07 '21 at 16:58

0 Answers0