pyforms的密码字段?
Password field for pyforms?
我的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._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 )
我的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._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 )