A Simple plug-in lock written in Python

Source: Internet
Author: User

Basic functions are implemented, but not beautiful enough
Alt + F4 is blocked, but Ctrl + Alt + Del is not blocked
 
 
 
#-*-Coding: UTF-8-*-u "is a built-in lock software. Author: Mpclast edited: Mat 2014 "import sysimport randomfrom PyQt4 import QtGui, QtCoreclass Example (QtGui. QWidget): def _ init _ (self): super (Example, self ). _ init _ () self. initUI () def initUI (self): # Label lbl1 = QtGui. QLabel (u'password: ', self) lbl1.setAlignment (QtCore. qt. alignRight) lbl2 = QtGui. QLabel (u'confirm password: ', self) # LineEdit self. le1 = QtGui. QLineEdit (self) self. le2 = QtGui. QLineEdit (self) # Pus HButton okButton = QtGui. QPushButton ("OK") okButton. clicked. connect (self. okButton_reponds) cancelButton = QtGui. QPushButton ("Cancel") cancelButton. clicked. connect (self. cancelButton_reponds) # hbox1 hbox1 = QtGui. QHBoxLayout () hbox1.addStretch (1) hbox1.addWidget (lbl1) hbox1.addWidget (self. le1) hbox1.addStretch (1) # hbox2 hbox2 = QtGui. QHBoxLayout () hbox2.addStretch (1) hbox2.addWidget (lbl2) hbox2.addW Idget (self. le2) hbox2.addStretch (1) # hbox3 hbox3 = QtGui. QHBoxLayout () hbox3.addStretch (1) hbox3.addWidget (okButton) hbox3.addWidget (cancelButton) hbox3.addStretch (1) vbox = QtGui. QVBoxLayout () vbox. addStretch (1) vbox. addLayout (hbox1) vbox. addLayout (hbox2) vbox. addLayout (hbox3) vbox. addStretch (1) self. setLayout (vbox) self. setGeometry (300,300,250,150) self. setWindowTitle (u'host lock') self. show () def OkButton_reponds (self): if not self. le1.text (). compare (self. le2.text (): if self. le1.text () = '': QtGui. QMessageBox. information (self, 'error', U'. Enter the password !! ') Else: self. lockScreen = LockScreen () self. lockScreen. password_lock = self. le1.text () self. close () else: QtGui. QMessageBox. information (self, 'error', u'inconsistent passwords ') self. le1.setText ('') self. le2.setText ('') def keyPressEvent (self, event): keyEvent = QtGui. QKeyEvent (event) if keyEvent. key () = QtCore. qt. key_Return: self. okButton_reponds () def cancelButton_reponds (self): self. le1.setText ('') self. le2.se TText ('') class LockScreen (QtGui. QWidget): def _ init _ (self): super (LockScreen, self ). _ init _ () self. initUI () # password self. password_lock = ''def initUI (self): # Label lbl1 = QtGui. QLabel (u'password: ', self) lbl1.setAlignment (QtCore. qt. alignRight) lbl2 = QtGui. QLabel (u'hanging ....... please do not tamper !! ', Self) lbl2.setAlignment (QtCore. qt. alignRight) lbl2.setFont (QtGui. QFont (u "文 ", 50, 20) # LineEdit self. le1 = QtGui. QLineEdit (self) # PushButton okButton = QtGui. QPushButton ("OK") okButton. clicked. connect (self. okButton_reponds) cancelButton = QtGui. QPushButton ("Cancel") cancelButton. clicked. connect (self. cancelButton_reponds) # hbox1 hbox1 = QtGui. QHBoxLayout () hbox1.addStretch (1) hbox1.addWidget (l Bl1) hbox1.addWidget (self. le1) hbox1.addStretch (1) # hbox2 hbox2 = QtGui. QHBoxLayout () hbox2.addStretch (1) hbox2.addWidget (lbl2) hbox2.addStretch (1) # hbox3 hbox3 = QtGui. QHBoxLayout () hbox3.addStretch (1) hbox3.addWidget (okButton) hbox3.addWidget (cancelButton) hbox3.addStretch (1) vbox = QtGui. QVBoxLayout () vbox. addStretch (1) vbox. addLayout (hbox2) vbox. addStretch (1) vbox. addLayout (hbox1) vbox. addLayo Ut (hbox3) vbox. addStretch (1) self. setLayout (vbox) self. setWindowFlags (QtCore. qt. windowStaysOnTopHint) self. showFullScreen () # backgroundimage self. setAutoFillBackground (True) palette = QtGui. QPalette () # palette. setBrush (QtGui. QPalette. window, QtGui. QBrush (QtGui. QPixmap ("g:/Python/pictures/" + str (random. randint (1,500) + ". jpg "). scaled (self. size (), QtCore. qt. ignoreAspectRatio, QtCore. qt. smoothTransfo Rmation) palette. setBrush (QtGui. QPalette. window, QtGui. QBrush (QtGui. QColor (170, 58,146) self. setPalette (palette) self. setWindowTitle (u'host lock') self. show () def okButton_reponds (self): if self. password_lock = self. le1.text (): QtCore. QCoreApplication. instance (). quit () elif self. le1.text () = '': QtGui. QMessageBox. information (self, 'error', U'. Enter the password !! ') Elif (not (self. le1.text () = '') and not self. password_lock = self. le1.text (): QtGui. QMessageBox. information (self, 'error', U' the password is incorrect !! ') Self. le1.setText ('') def keyPressEvent (self, event): keyEvent = QtGui. QKeyEvent (event) if keyEvent. key () = QtCore. qt. key_Return: self. okButton_reponds () # block Alt + F4 def closeEvent (self, event): event. ignore () def cancelButton_reponds (self): self. le1.setText ('') self. le2.setText ('') def main (): app = QtGui. QApplication (sys. argv) ex = Example () sys.exit(app.exe c _ () if _ name _ = '_ main _': main ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.