【问题标题】:Password field for pyforms?pyforms的密码字段?
【发布时间】:2017-08-08 22:06:24
【问题描述】:

我的 UI 是用 pyforms 编写的。

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

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

提前致谢!

  • 更新以反映社区准则

【问题讨论】:

  • 请将您的问题更新为一个问题。目前尚不清楚您在寻求什么帮助。请在此处查看指南:stackoverflow.com/help/how-to-ask 并重新表述您的问题。

标签: python-2.7 passwords pyforms


【解决方案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 )

【讨论】:

    【解决方案2】:

    您可以在项目文件夹中添加以下模块为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 )
    

    结果:

    【讨论】:

    • 非常感谢。正是我想要的!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 2011-02-28
    • 1970-01-01
    • 2011-03-02
    • 2012-12-11
    • 2010-12-25
    • 1970-01-01
    相关资源
    最近更新 更多