點擊按鈕qlineedit獲取內容:qlineedit獲取內容數字

QLineEdit控件與回顯模式

PyQt5學習記錄:QLineEdit

EchoMode()方法用來設置回顯示模式,有下列4種回顯模式。

  • Normal
  • NoEcho
  • Password
  • PasswordEchoOnEdit

代碼如下:

import sys
from PyQt5.QtWidgets import QApplication,QWidget,QLineEdit,QFormLayout

class QLineEditDemo(QWidget):
    def __init__(self):
        super().__init__()
        self.setupUI()

    def setupUI(self):
        # 創建4個演示用的QLineEdit
        self.lineEdit_1 = QLineEdit(self)
        self.lineEdit_2 = QLineEdit(self)
        self.lineEdit_3 = QLineEdit(self)
        self.lineEdit_4 = QLineEdit(self)

        # 設置placehoder
        self.lineEdit_1.setPlaceholderText("normal")
        self.lineEdit_2.setPlaceholderText("noEcho")
        self.lineEdit_3.setPlaceholderText("password")
        self.lineEdit_4.setPlaceholderText("passwordEchoOnEdit")

        # 設置回顯示模式

        self.lineEdit_1.setEchoMode(QLineEdit.Normal)
        self.lineEdit_2.setEchoMode(QLineEdit.NoEcho)
        self.lineEdit_3.setEchoMode(QLineEdit.Password)
        self.lineEdit_4.setEchoMode(QLineEdit.PasswordEchoOnEdit)

        # 創建一個formLayout
        self.formLayout = QFormLayout()
        self.formLayout.addRow("normal",self.lineEdit_1)
        self.formLayout.addRow("noEcho", self.lineEdit_2)
        self.formLayout.addRow("password", self.lineEdit_3)
        self.formLayout.addRow("passwordEchoOnEdit", self.lineEdit_4)
        self.setLayout(self.formLayout)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = QLineEditDemo()
    mainWindow.show()

    sys.exit(app.exec_())

原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/225302.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
投稿專員的頭像投稿專員
上一篇 2024-12-09 14:43
下一篇 2024-12-09 14:43

相關推薦

發表回復

登錄後才能評論