qlineedit文本改变时_PyQt5 QLineEdit(单行编辑器) 学习

QLineEdit is a widget that allows to enter and edit a single line of plain text. There are undo and redo, cut and paste, and drag & drop functions available for the widget.

代码:

# coding='utf-8'

from PyQt5.QtWidgets import QApplication, QWidget,\

QLineEdit, QLabel

import sys

class Gui(QWidget):

def __init__(self):

super(Gui, self).__init__()

self.start()

def start(self):

# 创建基于主窗体的标签

self.label = QLabel(self)

self.label.move(60, 40)

# 创建基于主窗体的单行输入框

line_edit = QLineEdit(self)

line_edit.move(60, 100)

# 将单行输入框的文本改变信号与self.on_changed槽联系起来

line_edit.textChanged[str].connect(self.on_changed)

self.setGeometry(300, 300, 280, 170)

self.setWindowTitle('单行输入框')

self.show()

# 每当单行输入控件的内容改变时触发

def on_changed(self, text):

# 每当单行输入控件的内容改变时就将该\

# 单行输入剩余的内容写入label

self.label.setText(text)

# label的adjustSize方法可以\

# 根据label里面文本的长度动态调整label控件的长度

self.label.adjustSize()

app = QApplication(sys.argv)

gui = Gui()

sys.exit(app.exec_())

运行结果:

image.png

你可能感兴趣的:(qlineedit文本改变时)