title: How to design countdown with Qt
body: <p>The code below creates a single <code>QLabel</code> and starts a countdown. Every second it prints a current time and how many seconds left.</p>
  
  <p><a href="https://i.stack.imgur.com/ECv4W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ECv4W.png" alt="enter image description here"></a></p>
  
  <p>Aside from printing the current time (Time now) I would like to print what time it is going to be when the count down reached the end. So the resulting message would look like this:</p>
  
  <pre><code>"Time now: 20:00:01. Countdown ends at: 20:00:16"
  </code></pre>
  
  <p>How to achieve it?</p>
  
  <pre><code>import datetime
  from PyQt4 import QtGui, QtCore
  app = QtGui.QApplication([])
  
  label = QtGui.QLabel()
  label.resize(360, 40)
  label.show()
  
  count = 15
  def countdown():
      global count 
      if count &lt; 1:
          count = 15
      label.setText( 'Time now: %s. Seconds left: %s'%(datetime.datetime.now().strftime("%H:%M:%S"), count))
      count = count - 1
  
  timer = QtCore.QTimer()
  timer.timeout.connect(countdown)
  timer.start(1000)
  
  app.exec_()
  </code></pre>
  
  <h1>Working solution:</h1>
  
  <p>(thanks to eyllanesc):</p>
  
  <p><a href="https://i.stack.imgur.com/unhsU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/unhsU.png" alt="enter image description here"></a></p>
  
  <pre><code>import datetime
  from PyQt4 import QtGui, QtCore
  app = QtGui.QApplication([])
  
  label = QtGui.QLabel()
  label.resize(360, 40)
  label.show()
  
  count = 15
  def countdown():
      global count 
      if count &lt; 1:
          count = 15
      now = datetime.datetime.now()
      label.setText( 'Time now: %s. End time: %s. Seconds left: %s'%(now.strftime("%H:%M:%S"), (now + datetime.timedelta(seconds=count)).strftime("%H:%M:%S"), count))
      count = count - 1
  
  interval = 1200
  timer = QtCore.QTimer()
  timer.timeout.connect(countdown)
  timer.start(1000)
  
  app.exec_()
  </code></pre>