D
D
Danya  2020-06-20 00:55:52
Python
Danya  , 2020-06-20 00:55:52

How to pass LineEdit data to label?

We need to pass the LineEdit value to the Label in real time without pressing any buttons.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-06-20
@MrBrainop

without pressing any buttons.
I wonder how you will change the contents of the LineEdit, telepathically? ¯\_(ツ)_/¯
If I understand correctly, you need to react to text editing in LineEdit, and output text from it to the label:
import sys
from PySide2.QtCore import Qt
from PySide2.QtWidgets import (QApplication, QWidget,
    QPushButton, QLabel, QVBoxLayout, QLineEdit)
 
 
class MyWidget(QWidget):
    def __init__(self):
        QWidget.__init__(self)

        self.my_label = QLabel()
        self.line_edit = QLineEdit()
        self.my_label.setAlignment(Qt.AlignCenter)
        
        self.layout = QVBoxLayout()
        self.layout.addWidget(self.my_label)
        self.layout.addWidget(self.line_edit)
        self.setLayout(self.layout)

        self.line_edit.textChanged.connect(self.magic) # Реагируем на события изменения текста
    
    def magic(self):
        self.my_label.setText(self.line_edit.text()) # Выводим в label текст из lineedit
 
if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = MyWidget()
    widget.resize(200, 150)
    widget.show()
    sys.exit(app.exec_())

5eed545b0dbf3603218681.gif

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question