凌的博客

您现在的位置是: 首页 > 学无止境 > python > 

python

28. PyQt6 QLineEdit

2023-10-17 python 518
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel, QLineEdit
from PyQt6.QtGui import QGuiApplication


class App(QMainWindow):

    def __init__(self):
        super().__init__()
        self.lbl = None
        self.initUI()

    def initUI(self):
        self.setWindowTitle("PyQt6 QLineEdit")

        self.lbl = QLabel(self)
        q_text = QLineEdit(self)

        q_text.move(60, 100)
        self.lbl.move(60, 40)

        q_text.textChanged[str].connect(self.changeText)

        self.setGeometry(100, 100, 400, 300)
        self.center()

    def changeText(self, text):
        self.lbl.setText(text)
        self.lbl.adjustSize()

    def center(self):
        qr = self.frameGeometry()
        cp = QGuiApplication.primaryScreen().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())


if __name__ == "__main__":
    app = QApplication(sys.argv)
    cls_app = App()
    cls_app.show()
    sys.exit(app.exec())

image.png

文章评论

0条评论