pyforms的密码字段?

问题描述 投票:1回答:2

我的UI用pyforms编写。

我如何实现密码字段? (例如,而不是“ P @ ssW0rd”,它将显示“ ********”)。

我发现我可以利用QLineEdit.EchoMode,但是不确定如何实现。

提前感谢!

  • 已更新以反映社区准则
python-2.7 passwords pyforms
2个回答
0
投票

您可以在项目文件夹中将以下模块作为ControlPasswordText.py添加:

from pysettings import conf
from pyforms.Controls import ControlText

from PyQt4.QtGui import QLineEdit

class ControlPasswordText(ControlText):
    def __init__(self, *args, **kwargs):
        super(ControlPasswordText, self).__init__(*args, **kwargs)
        self.form.lineEdit.setEchoMode(QLineEdit.Password)

这是您将如何使用它:

import pyforms
from   pyforms          import BaseWidget
from   pyforms.Controls import ControlText
from   pyforms.Controls import ControlButton

# Importing the module here
from ControlPasswordText import ControlPasswordText

class SimpleExample1(BaseWidget):

    def __init__(self):
        super(SimpleExample1,self).__init__('Simple example 1')

        #Definition of the forms fields
        self._username     = ControlText('Username')
        # Using the password class
        self._password    = ControlPasswordText('Password')


#Execute the application
if __name__ == "__main__":   pyforms.startApp( SimpleExample1 )

结果:

enter image description here


1
投票

Pyforms还包括一个密码框。您也可以使用self._password = ControlPassword('Password')

简单地说:

import pyforms
from pyforms.basewidget import BaseWidget
from pyforms.controls import ControlText
from pyforms.controls import ControlButton
from pyforms.controls import ControlPassword


class Login(BaseWidget):

    def __init__(self):
        super(Login,self).__init__('Simple example 1')

        #Definition of the forms fields
        self._username  = ControlText('Username', 'Default value')
        self._password = ControlPassword('Password')

        self._button     = ControlButton('Login')
        self._button.value = self.__buttonAction #Define button action

    def __buttonAction(self):
        """Button action event"""
        username = self._username.value
        password = self._password.value
        credentials = (username, password)
        return credentials

#Execute the application
if __name__ == "__main__":
    pyforms.start_app( Login )
© www.soinside.com 2019 - 2024. All rights reserved.