The basics can be realized, but not beautiful enough.
Shielded the ALT+F4, but Ctrl+alt+del failed to shield
#-*-Coding:utf-8-*-U "" "A hanging machine lock software.
AUTHOR:MPC last Edited:mat 2014 "" "The import sys import random from PyQt4 import Qtgui, Qtcore
Class 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) #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 (LBL1) Hbox1.addwidget (Self.le1) hbox1.addstretch (1) #hbox2 hbox2 = Qtgui.qhboxlayout () Hbox2.addstretch (1) hbox2.addwidget (LBL2) hbox2.addwidget (self.le2) hbox2.addstre TCH (1) #hbox3 hbox3 = Qtgui.qhboxlayout () hbox3.addstretch (1) hbox3.addwidget (OKBU Tton) Hbox3.addwidget (CancelButton) hbox3.addstretch (1) vbox = Qtgui.qvboxlay Out () Vbox.addstretch (1) vbox.addlayout (hbox1) vbox.addlayout (hbox2) vbox.addlayou T (HBOX3) Vbox.addstretch (1) self.setlayout (vbox) self.set Geometry (Self.setwindowtitle) (U ' Hang Machine 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 ') Please type the password!! ') Else:self.lockScreen = Lockscreen () Self.lockScreen.password_lock = Self.le1.text () Self.close () else:QtGui.QMessageBox.information (self, ' Error ',
U ' password inconsistent ') 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.setText (') class Lockscreen (qtgui.qwidget): de
F __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 ' Hang up .....) Please don't move!!
', self ' lbl2.setalignment (QtCore.Qt.AlignRight) Lbl2.setfont (Qtgui.qfont (U "Chinese Xingkai", 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 (LBL1) 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.addlayout (HBOX3) vbox.addstretch (1) Self.setlayout (VBox) self.setwindowflags (QtCore.Qt.WindowStaysOnTopHint) sel F.showfullscreen () #backgroundimage self.setautofillbackground (True) palette = Qtgui.qpalette () # Palette.setbrush (QtGui.QPalette.Window, Qtgui.qbrush qtgui.qpixmap ("g:/python/pictures/" +st R (Random.randint (1)) + ". jpg"). Scaled (Self.size (), QtCore.Qt.IgnoreAspectRatio, QtCore.Qt.SmoothTransformation )) Palette.setbrush (QtGui.QPalette.Window, Qtgui.qbrush (Qtgui.qcolor (170, 146))) Self.setpalette (
Palette Self.setwindowtitle (U ' Hang Machine lock ') self.show () def okbutton_reponds (self): if Self.password_lock = = Self.le1.text (): Qtcore.qcoreappli Cation.instance (). Quit () elif self.le1.text () = = ': QtGui.QMessageBox.information (Self, ' Error ', U ' Please type the password!! ') elif (Not (self.le1.text () = = ') and not self.password_lock = = Self.le1.text ()): Qtgui.qmessag Ebox.information (self, ' error ', u ' password wrong!!) ') Self.le1.setText (') def keypressevent (Self, event): KeyEvent = Qtgui. Qkeyevent (Event) if keyevent.key () = = QtCore.Qt.Key_Return:self.
Okbutton_reponds () #屏蔽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.ex It (APP.EXEC_ ()) If __name__ = = ' __main__ ': Main ()
Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/