Skip to content

Instantly share code, notes, and snippets.

@keimina
Created August 19, 2014 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keimina/ebc0626818e184d20c29 to your computer and use it in GitHub Desktop.
Save keimina/ebc0626818e184d20c29 to your computer and use it in GitHub Desktop.
from PySide.QtGui import *
from PySide.QtCore import QTimer
app = QApplication([])
widget = QWidget()
textbox = QLineEdit()
startbutton = QPushButton("start/stop")
resetbutton = QPushButton("reset")
timelabel = QLabel("00:00:00")
counttimer = QTimer()
hboxlayout = QHBoxLayout()
vboxlayout = QVBoxLayout()
hboxlayout.addWidget(textbox)
vboxlayout.addWidget(startbutton)
vboxlayout.addWidget(resetbutton)
hboxlayout.addLayout(vboxlayout)
hboxlayout.addWidget(timelabel)
widget.setLayout(hboxlayout)
timecnt = 0
def updatewidget():
global widget, textbox, timecnt, timelabel
timecnt += 1
timelabel.setText(u"%02d:%02d:%02d"%(timecnt/3600, timecnt%3600/60, timecnt%60))
counttimer.timeout.connect(updatewidget)
state = 1
def startclicked():
global counttimer, state
if state==1:
counttimer.start(1000)
state = 0
else:
counttimer.stop()
state = 1
startbutton.clicked.connect(startclicked)
def resetclicked():
global timelabel, timecnt
timelabel.setText("00:00:00")
timecnt = 0
resetbutton.clicked.connect(resetclicked)
widget.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment