#!/usr/bin/python#-*-coding:utf-8-*-#shutdown.py
import sys#导入
importosfrom PyQt4.QtCore import *
from PyQt4.QtGui import *
classShutDown(QWidget):def __init__(self):
super(ShutDown, self).__init__()
self.setWindowTitle('PyQt')
self.hourLabel= QLabel(u'小时')#标签
self.minuteLabel = QLabel(u'分钟')
self.secondLabel= QLabel(u'秒')
self.shutDownButton= QPushButton()#按钮
self.shutDownButton.setText(u'关机')
self.shutDownButton.clicked.connect(self.confirm_shutdown)
self.rebootButton=QPushButton()
self.rebootButton.setText(u'重启')
self.rebootButton.clicked.connect(self.confirm_reboot)
self.logoffButton=QPushButton()
self.logoffButton.setText(u'注销')
self.logoffButton.clicked.connect(self.confirm_logoff)
self.hourSpinBox=QSpinBox()
self.hourSpinBox.setRange(0,1000)
self.hourSpinBox.setSingleStep(1)
self.hourSpinBox.setValue(0)
self.minuteSpinBox=QSpinBox()
self.minuteSpinBox.setRange(0,1000)
self.minuteSpinBox.setSingleStep(1)
self.minuteSpinBox.setValue(0)
self.secondSpinBox=QSpinBox()
self.secondSpinBox.setRange(0,1000)
self.secondSpinBox.setSingleStep(1)
self.secondSpinBox.setValue(0)
self.layout= QGridLayout()#网格布局
self.layout.addWidget(self.hourLabel,1,0)
self.layout.addWidget(self.hourSpinBox,1,1)
self.layout.addWidget(self.minuteLabel,1,2)
self.layout.addWidget(self.minuteSpinBox,1,3)
self.layout.addWidget(self.secondLabel,1,4)
self.layout.addWidget(self.secondSpinBox,1,5)
self.layout.addWidget(self.shutDownButton,2,0,2,2)
self.layout.addWidget(self.rebootButton,2,2,2,2)
self.layout.addWidget(self.logoffButton,2,4,2,2)
self.setLayout(self.layout)defconfirm_shutdown(self):
self.time= (self.hourSpinBox.value() * 3600 + self.minuteSpinBox.value() * 60
+self.secondSpinBox.value())
shutdown= 'C:\Windows\System32\shutdown.exe -s -t' +str(self.time)
os.system(shutdown)
sys.exit(0)defconfirm_reboot(self):
reboot= 'C:\Windows\System32\shutdown.exe -r'os.system(reboot)
sys.exit(0)defconfirm_logoff(self):
logoff= 'C:\Windows\System32\shutdown.exe -l'os.system(logoff)
sys.exit(0)if __name__ == '__main__':
app=QApplication(sys.argv)
shutdown=ShutDown()
shutdown.show()
sys.exit(app.exec_())