Skip to content

python gui - PyQt4 精彩实例分析之电子钟

标签:python gui pyqt4 实例

PyQt4 精彩实例分析之电子钟,当然在写实例之前要先安装PyQt4模块。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 from PyQt4.QtGuiimport * from PyQt4.QtCoreimport * import sys       class DigiClock(QLCDNumber):      def __init__(self,parent=None):          super(DigiClock,self).__init__(parent)               p=self.palette()          p.setColor(QPalette.Window,Qt.red)          self.setPalette(p)                     self.setNumDigits(19)         self.dragPosition=None              self.setWindowFlags(Qt.FramelessWindowHint)          self.setWindowOpacity(0.5)               timer=QTimer(self)          self.connect(timer,SIGNAL("timeout()"),self.showTime)          timer.start(1000)               self.showTime()                  self.resize(500,60)           def mousePressEvent(self,event):          if event.button()==Qt.LeftButton:              self.dragPosition=event.globalPos()-self.frameGeometry().topLeft()              event.accept()          if event.button()==Qt.RightButton:              self.close()           def mouseMoveEvent(self,event):          if event.buttons() & Qt.LeftButton:              self.move(event.globalPos()-self.dragPosition)              event.accept()           def showTime(self):          time=QTime.currentTime()         date=QDate.currentDate()         text= date.toString("yyyy-MM-dd")+" "+time.toString("hh:mm:ss")              self.display(text)           app=QApplication(sys.argv)  form=DigiClock()  form.show()  app.exec_()

部分信息收集于网络,若有侵权请联系我们.