2017-08-08 78 views
0

我的用戶界面是用pyforms編寫的。pyforms的密碼字段?

如何實現密碼字段? (EG。而不是'P @ ssW0rd'它會顯示'********')。

我發現我可以利用QLineEdit.EchoMode,但不確定如何實現。

在此先感謝!

  • 更新,以反映社會準則
+0

請更新您的問題是一個問題。目前還不清楚你在尋求什麼幫助。請在此處查看指導原則:https://stackoverflow.com/help/how-to-ask並更改您的問題。 – Ben

回答

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

+0

謝謝一堆。正是我在找什麼! – CraigJ