** >>> 点击进入:pyqt5专栏<<<**
老师原课件下载地址:
有积分的朋友,支持下我,打赏也OK。
不下载也可以,我每节课会吧代码贴出来
P31课时32.QLineEdit控件与回显模式(EchoMode)
四种回显模式
'''
QLineEdit控件与回显模式
基本功能:输入单行的文本
EchoMode(回显模式)
4种回显模式
1. Normal 输入什么显示什么
2. NoEcho 输入什么不显示,但是已经提交了
3. Password 输入什么都显示 ****
4. PasswordEchoOnEdit 输入什么,丢失目标以后显示*****
Mac : Command Windows:Control
'''
from PyQt5.QtWidgets import *
import sys
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()
passwordEchoOnEditLineEdit = QLineEdit()
formLayout.addRow("Normal",normalLineEdit)
formLayout.addRow("NoEcho", noEchoLineEdit)
formLayout.addRow("Password",passwordLineEdit)
formLayout.addRow("PasswordEchoOnEdit",passwordEchoOnEditLineEdit)
# placeholdertext
normalLineEdit.setPlaceholderText("Normal")
noEchoLineEdit.setPlaceholderText("NoEcho")
passwordLineEdit.setPlaceholderText("Password")
passwordEchoOnEditLineEdit.setPlaceholderText("PasswordEchoOnEdit")
normalLineEdit.setEchoMode(QLineEdit.Normal)
noEchoLineEdit.setEchoMode(QLineEdit.NoEcho)
passwordLineEdit.setEchoMode(QLineEdit.Password)
passwordEchoOnEditLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit)
self.setLayout(formLayout)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = QLineEditEchoMode()
main.show()
sys.exit(app.exec_())
class QLineEditEchoMode(QWidget) :
formLayout = QFormLayout()
normalLineEdit = QLineEdit()
noEchoLineEdit = QLineEdit()
passwordLineEdit = QLineEdit()
passwordEchoOnEditLineEdit = QLineEdit()
formLayout.addRow("Normal",normalLineEdit)
formLayout.addRow("NoEcho", noEchoLineEdit)
formLayout.addRow("Password",passwordLineEdit)
formLayout.addRow("PasswordEchoOnEdit",passwordEchoOnEditLineEdit)
一个一个往里拖呗
Form可以随便选一个,这样可以起到自动调整大小的效果
formlayout 选择adjust size, 自己体会吧
这里不做解释了,text快速查找,不懂的,看课时30
设置标签名
normalLineEdit.setPlaceholderText("Normal")
noEchoLineEdit.setPlaceholderText("NoEcho")
passwordLineEdit.setPlaceholderText("Password")
passwordEchoOnEditLineEdit.setPlaceholderText("PasswordEchoOnEdit")
normalLineEdit.setEchoMode(QLineEdit.Normal)
noEchoLineEdit.setEchoMode(QLineEdit.NoEcho)
passwordLineEdit.setEchoMode(QLineEdit.Password)
passwordEchoOnEditLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit)
# -*- coding:utf-8 -*-
'''
@Author: knocky
@Blog: https://blog.csdn.net/zzx188891020
@E-mail: [email protected]
@File: class32.py
@CreateTime: 2020/5/8 17:19
'''
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5 import uic
class QLabelDemo() :
def __init__(self):
super().__init__()
self.ui = uic.loadUi("../ui_package/class32.ui")
if __name__ == '__main__':
app = QApplication(sys.argv)
main = QLabelDemo()
main.ui.show()
sys.exit(app.exec_())