Skip to content

Instantly share code, notes, and snippets.

@SlyCodePanda
Last active February 17, 2020 05:20
Show Gist options
  • Save SlyCodePanda/2f7ca1ec911f773dc59289ca71de26e4 to your computer and use it in GitHub Desktop.
Save SlyCodePanda/2f7ca1ec911f773dc59289ca71de26e4 to your computer and use it in GitHub Desktop.
Code for creating a digital clock
import sys
from PyQt4 import QtGui, QtCore
from time import strftime
'''
http://thecodeinn.blogspot.com/2013/07/tutorial-pyqt-digital-clock.html
'''
class Main(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.initUI()
def initUI(self):
self.timer = QtCore.QTimer(self)
self.timer.timeout.connect(self.Time)
self.timer.start(1000)
self.lcd = QtGui.QLCDNumber(self)
self.lcd.display(strftime("%H"+":"+"%M"))
self.setCentralWidget(self.lcd)
#---------Window settings --------------------------------
self.setGeometry(300,300,250,100)
self.setWindowTitle("Clock")
#-------- Slots ------------------------------------------
def Time(self):
self.lcd.display(strftime("%H"+":"+"%M"))
def main():
app = QtGui.QApplication(sys.argv)
main = Main()
main.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment