pyforms的密码字段?

时间:2017-08-08 22:06:24

标签: python-2.7 passwords pyforms

我的用户界面是用pyforms编写的。

如何实施密码字段? (EG。而不是'P @ ssW0rd'它会显示'********')。

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

提前致谢!

  • 已更新以反映社区准则

2 个答案:

答案 0 :(得分: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 )

答案 1 :(得分: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