Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8611517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:23:47+00:00 2026-06-12T04:23:47+00:00

I’ve searched internet for days but can figure out how to put this code

  • 0

I’ve searched internet for days but can figure out how to put this code to work. It’s a very simple gui (made on Qt Designer) with a lcd and a button. I want it to on the press of the button to start the countdown from 180 seconds back. In the first moment i was able to make to button decrease in one the value but after trying so many different things nothing is working. Can someone help me please? Probably is something very simple. Thank you.

# -*- coding: utf-8 -*-
import sys
import time
from PyQt4 import QtCore, QtGui
from relogio import Ui_relogiocc

class StartQT4(QtGui.QMainWindow):
 def __init__(self, parent=None):
  QtGui.QWidget.__init__(self, parent)
  self.ui = Ui_relogiocc()
  self.ui.setupUi(self)
  self.timer = QtCore.QTimer()
  text = "%d:%02d" % (180/60,180 % 60)
  self.ui.QLCDNumber.display(text)
  self.timer.start(1000)
  self.ui.iniciar.clicked.connect(self.updateTimerDisplay)


 def updateTimerDisplay(self):
  self.inicio = 180
  while self.inicio != 0:
   text = "%d:%02d" % (self.inicio/60,self.inicio % 60)
   self.ui.QLCDNumber.display(text)
   self.inicio - 1
  else:
   self.timer.stop()  


if __name__ == "__main__":
 app = QtGui.QApplication(sys.argv)
 myapp = StartQT4()
 myapp.show()
 sys.exit(app.exec_())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:23:48+00:00Added an answer on June 12, 2026 at 4:23 am

    It seems there are a number of things you are missing here.

    Firstly, the timer emits a timeout() signal whenever each timeout period completes. In your case, this is every one second. However, you’re not connecting this signal to anything.

    Secondly, your updateTimerDisplay contains the following line:

       self.inicio - 1
    

    This reads the value of self.inicio, subtracts 1 from it and then throws the result away. Because self.inicio‘s value doesn’t change your updateTimerDisplay method goes into an infinite loop.

    I’m guessing you meant

       self.inicio -= 1
    

    instead, which assigns the new value of self.inicio back to itself.

    Ultimately, however, it seems you’re trying to use your updateTimerDisplay method to start the timer, count it down and also update the display of the timer. I’d recommend breaking this method up to smaller methods.

    Firstly, updateTimerDisplay should only update the display of the timer:

     def updateTimerDisplay(self):
      text = "%d:%02d" % (self.inicio/60,self.inicio % 60)
      self.ui.QLCDNumber.display(text)
    

    Secondly, you’ll want a method to start the timer. Something like the following should do:

     def startTimer(self):
      self.inicio = 180
      self.updateTimerDisplay()
      self.timer.start(1000)
    

    Of course, you’ll also need to connect your iniciar button’s clicked() signal to this function, instead of to updateTimerDisplay.

    Finally, you’ll need a method that handles a tick from the timer. Something like the following should do:

     def timerTick(self):
      self.inicio -= 1
      self.updateTimerDisplay()
      if self.inicio <= 0:
       self.timer.stop()
    

    You’ll also need to connect the timeout() signal of the timer to this function, using something like:

      self.timer.timeout.connect(self.timerTick)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.