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):
# 創(chuàng)建基于主窗體的標(biāo)簽
self.label = QLabel(self)
self.label.move(60, 40)
# 創(chuàng)建基于主窗體的單行輸入框
line_edit = QLineEdit(self)
line_edit.move(60, 100)
# 將單行輸入框的文本改變信號與self.on_changed槽聯(lián)系起來
line_edit.textChanged[str].connect(self.on_changed)
self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('單行輸入框')
self.show()
# 每當(dāng)單行輸入控件的內(nèi)容改變時觸發(fā)
def on_changed(self, text):
# 每當(dāng)單行輸入控件的內(nèi)容改變時就將該\
# 單行輸入剩余的內(nèi)容寫入label
self.label.setText(text)
# label的adjustSize方法可以\
# 根據(jù)label里面文本的長度動態(tài)調(diào)整label控件的長度
self.label.adjustSize()
app = QApplication(sys.argv)
gui = Gui()
sys.exit(app.exec_())
運(yùn)行結(jié)果:
image.png
總結(jié)
以上是生活随笔為你收集整理的qlineedit文本改变时_PyQt5 QLineEdit(单行编辑器) 学习的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php对mysql基础操作_php+my
- 下一篇: 古风诗意情侣网名100个