Last active
February 17, 2020 05:20
-
-
Save SlyCodePanda/2f7ca1ec911f773dc59289ca71de26e4 to your computer and use it in GitHub Desktop.
Code for creating a digital clock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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