文章目录
- QLineEdit
- 更新和获取文本框内容
- 设置为无边框
QLineEdit
更新和获取文本框内容
更新:QLineEdit().setText(text)
获取:QLineEdit().text()
from PyQt5.QtWidgets import *
import sys
app = QApplication(sys.argv)
window = QWidget()
window.resize(200, 200)
lineEdit = QLineEdit(window)
lineEdit.setText('1234')
button1 = QPushButton('更新', window)
button1.clicked.connect(lambda: lineEdit.setText('更新内容'))
button1.move(50, 100)
button2 = QPushButton('获取', window)
button2.clicked.connect(lambda: print(lineEdit.text()))
button2.move(50, 150)
window.show()
sys.exit(app.exec_())
运行结果:
设置为无边框
无边框样式:QLineEdit().setStyleSheet('border: none;')
以以上代码为例:
lineEdit.setStyleSheet('border: none;')
运行结果: