python自写软件(三)

 1 from PyQt5.Qt import QLCDNumber
 2 from PyQt5.QtGui import QPalette, QBrush, QPixmap
 3 from PyQt5.QtWidgets import QApplication, QHBoxLayout, QVBoxLayout, QPushButton, QWidget
 4 import sys
 5 import time
 6 from PyQt5.Qt import QTime, QTimer
 7 import time
 8 
 9 class clock(QWidget):
10     def __init__(self):
11         super().__init__()
12         self.num = 0
13         self.init()
14         self.paletter = QPalette()
15         self.paletter.setBrush(self.backgroundRole(),
16                                QBrush(QPixmap('H:\\CLOCK\\tokyouniversity.jpg')))
17         self.setPalette(self.paletter)
18         self.flag = 1
19         self.s = 0
20         self.h = 0
21         self.m = 0
22 
23     def init(self):
24         self.setWindowTitle("学习计时时钟")
25         self.resize(600, 400)
26         self.lcd = QLCDNumber(20, self)
27         stop = QPushButton("STOP")
28         stop.setStyleSheet('background-color:rgb(180,180,180,255);font-size:20px;color:rgb(0,0,0,255);')
29         stop.clicked.connect(self.stop)
30         resume = QPushButton("RESUME")
31         resume.setStyleSheet('background-color:rgb(180,180,180,255);font-size:20px;color:rgb(0,0,0,255);')
32         resume.clicked.connect(self.resume)
33         begin = QPushButton("BEGIN")
34         begin.setStyleSheet('background-color:rgb(180,180,180,255);font-size:20px;color:rgb(0,0,0,255);')
35         begin.clicked.connect(self.begin)
36         hbox = QHBoxLayout()
37         shiro = QWidget()
38         shiro.setLayout(hbox)
39         hbox.addWidget(begin)
40         hbox.addWidget(resume)
41         hbox.addWidget(stop)
42         vbox = QVBoxLayout()
43         vbox.addWidget(self.lcd)
44         vbox.addWidget(shiro)
45         self.setLayout(vbox)
46 
47     def getResult(self):
48         self.num += 1
49         if self.flag == 1:
50             self.s += 1
51         if self.s == 60:
52             self.s = 0
53             self.m += 1
54         if self.m == 60:
55             self.m = 0
56             self.h += 1
57         time = QTime(self.h, self.m, self.s)
58         text = time.toString('hh:mm:ss')
59 
60         self.lcd.display(text)
61 
62     def begin(self):
63         self.timer = QTimer()
64         self.timer.setInterval(1000)
65         self.timer.start()
66         self.timer.timeout.connect(self.getResult)
67 
68     def stop(self):
69         self.flag = 0
70 
71     def resume(self):
72         self.flag = 1
73 
74 
75 if __name__ == '__main__':
76     app = QApplication(sys.argv)
77     myclock = clock()
78     myclock.show()
79     sys.exit(app.exec())

实现闹钟功能

 

 图片想去的东京大学

posted @ 2020-05-07 08:14  世界を変える御宅族  阅读(188)  评论(0编辑  收藏  举报