Python 2.7 pyforms的密码字段?

Python 2.7 pyforms的密码字段?,python-2.7,passwords,pyforms,Python 2.7,Passwords,Pyforms,我的UI是用pyforms编写的 如何实现密码字段?(例如,代替'P@ssW0rd'它将显示'********') 我发现我可以利用QLineEdit.EchoMode,但不确定如何实现 提前谢谢 更新以反映社区准则 您可以将以下模块作为ControlPasswordText.py添加到项目文件夹中: from pysettings import conf from pyforms.Controls import ControlText from PyQt4.QtGui import QLi

我的UI是用pyforms编写的

如何实现密码字段?(例如,代替'P@ssW0rd'它将显示'********')

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

提前谢谢

  • 更新以反映社区准则

您可以将以下模块作为
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 )
结果:


Pyforms还包括一个密码框。你也可以使用
self.\u 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 )

请将您的问题更新为问题。不清楚你在寻求什么帮助。请阅读这里的指南:并重新表述你的问题。非常感谢。正是我要找的!