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文本改变时_PyQt5 QLineEdit(单行编辑器) 学习的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php对mysql基础操作_php+my
- 下一篇: 古风诗意情侣网名100个