codeFlowType:
codeWrite
codeFlowLang:
Python
Реализуйте несколько событий «проверка введённого текста в textChanged».
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QLineEdit
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Text Changed Events')
layout = QVBoxLayout()
self.setLayout(layout)
self.label = QLabel()
layout.addWidget(self.label)
self.textbox = QLineEdit()
self.textbox.textChanged.connect(self.on_text_changed)
layout.addWidget(self.textbox)
def on_text_changed(self, text):
self.label.setText(f'Text changed to: {text}')
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
Результат: