官方文档:https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QLineEdit.html
使用前导入该组件:
from PySide6.QtWidgets import QLineEdit
构造方法
# 输入框
QLineEdit([_parent=None_])
输入框,最大文本长度设置为32767个字符。
常用api
# 返回输入框内容
text()
# 设置输入框内容
setText(text:str)
# 提示文本
setPlaceholderText(text:str)
"""
设置文本显示的回显模式
QLineEdit.Password 显示密码掩码字符
"""
setEchoMode(mode)
#清除内容
clear()
例子
from PySide6.QtWidgets import QLineEdit,QLabel,QFormLayout, QWidget, QApplication
class Example(QWidget):
def __init__(self):
super().__init__()
self.layout = QFormLayout()
self.username = QLabel("username")
self.password = QLabel("password")
# 创建LineEdit
self.input_username = QLineEdit()
self.input_password = QLineEdit()
# 设置提示符
self.input_username.setPlaceholderText("username")
self.input_password.setPlaceholderText("password")
# 设置模式为密码模式
self.input_password.setEchoMode(QLineEdit.Password)
self.layout.addRow(self.username, self.input_username)
self.layout.addRow(self.password, self.input_password)
self.setLayout(self.layout)
if __name__ == "__main__":
app = QApplication([])
btnTest = Example()
btnTest.show()
app.exec()