kanryu

DigitalClock - PySide Sample

Oct 28th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import sys
  4. import PySide.QtCore as QtCore
  5. import PySide.QtGui as QtGui
  6.  
  7. class DigitalClock(QtGui.QLCDNumber):
  8.     def __init__(self, parent=None):
  9.         super(DigitalClock, self).__init__(parent)
  10.  
  11.         self.setSegmentStyle(QtGui.QLCDNumber.Filled)
  12.  
  13.         timer = QtCore.QTimer(self)
  14.         timer.timeout.connect(self.showTime)
  15.         timer.start(1000)
  16.  
  17.         self.showTime()
  18.  
  19.         self.setWindowTitle("Digital Clock")
  20.         self.resize(150, 60)
  21.  
  22.     def showTime(self):
  23.         time = QtCore.QTime.currentTime()
  24.         text = time.toString('hh:mm')
  25.         if (time.second() % 2) == 0:
  26.             text = text[:2] + ' ' + text[3:]
  27.  
  28.         self.display(text)
  29.  
  30.  
  31. if __name__ == '__main__':
  32.  
  33.  
  34.     app = QtGui.QApplication(sys.argv)
  35.     clock = DigitalClock()
  36.     clock.show()
  37.     sys.exit(app.exec_())
  38.  
  39.  
Advertisement
Add Comment
Please, Sign In to add comment