Implementing a stoppable stopwatch in python and PySide
<p>I'm trying to create a simple stopwatch in python / pySide with a time display and simple start and stop buttons:</p>

<pre><code>from PySide import QtGui, QtCore
import time
import datetime
import sys

class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.stopwatchDisplayLabel = QtGui.QLabel("0:00:00", self)
        self.startButton = QtGui.QPushButton("Start", self)
        self.stopButton = QtGui.QPushButton("Stop", self)

        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.stopwatchDisplayLabel)
        layout.addWidget(self.startButton)
        layout.addWidget(self.stopButton)
        self.createEvents()
        self.setLayout(layout)

    def createEvents(self):
        self.startButton.clicked.connect(self.startStopwatch)
        self.stopButton.clicked.connect(self.stopStopwatch)

    def updateDisplay(self, displayTime):
        stopWatchDisplay = str(datetime.timedelta(seconds = displayTime))
        print(stopWatchDisplay)
        self.stopwatchDisplayLabel.setText(stopWatchDisplay)
        self.stopwatchDisplayLabel.repaint()

    def startStopwatch(self, numberOfSeconds = 10):
        self.fullCountdown = numberOfSeconds
        self.timerRunning = True
        while self.fullCountdown &gt;= 0 and self.timerRunning:
            self.updateDisplay(self.fullCountdown)
            time.sleep(1)
            self.fullCountdown -= 1

    def stopStopwatch(self):
        self.timerRunning = False

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())
</code></pre>

<p>The problem I'm having is that the "stop" button becomes unresponsive once the "start" button is pressed.  I've got a feeling that the issue is that the GUI won't response whilst the sleep command is running (as this makes the whole process sleep) and the only way to stop it is to hit the "stop" button at exactly the time the sleep command isn't running.</p>

<p>Is the way around this to create a separate thread for the timing?</p>
