Created
August 19, 2014 08:47
-
-
Save keimina/ebc0626818e184d20c29 to your computer and use it in GitHub Desktop.
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
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