PyQt5基本窗口控件基本窗口控件—–QLineEdit
PyQt5学习之路,点击有pyqt5学习笔记
QLineEdit类是一个单行文本控件,可输入单行字符串,可以设置回显模式类是一个单行文本控件,可输入单行字符串,可以设置回显模式(Echomode)和掩码模式和掩码模式
1. 回显模式回显模式(Echomode)
回显模式就是当键盘被按下后,显示了什么
Normal 正常的回显模式
NoEcho 不回显模式(什么都没出现)
Password 密码
PasswordEchoOnEdit 先是显示,然后过了几秒就不显示
import sys
from PyQt5.QtWidgets import *
class QLineEditEchoMode(QWidget):
def __init__(self):
super(QLineEditEchoMode, self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('文本框的回显模式')
formLayout = QFormLayout()
normalLineEdit = QLineEdit()
noEchoLineEdit = QLineEdit()
passwordLineEdit = QLineEdit()
passwordEchoOnLineEdit = QLineEdit()
formLayout.addRow("Normal", normalLineEdit)
formLayout.addRow("noEcho", noEchoLineEdit)
formLayout.addRow("password", passwordLineEdit)
formLayout.addRow("passwordEchoOnEdit", passwordEchoOnLineEdit)
# placeoldertext 文本输入框内的灰色提示
normalLineEdit.setPlaceholderText("Normal")
noEchoLineEdit.setPlaceholderText("noEcho")
passwordLineEdit.setPlaceholderText("password")
passwordEchoOnLineEdit.setPlaceholderText("passwordEchoOnEdit")
normalLineEdit.setEchoMode(QLineEdit.Normal)
noEchoLineEdit.setEchoMode(QLineEdit.NoEcho)
passwordLineEdit.setEchoMode(QLineEdit.Password)
passwordEchoOnLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit)
self.setLayout(formLayout)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = QLineEditEchoMode()
main.show()
sys.exit(app.exec_())
2. 校验器校验器
比如只能限制输入整数或满足一定条件的字符串
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIntValidator, QDoubleValidator, QRegExpValidator
from PyQt5.QtCore import QRegExp
评论10