The "sunset_time = time(18,30,00)" line yields a 'QTime' object is NOT callable error.... what am I doing wrong?..My application is supposed to get and display current time then set sunset time and then subtract current time from sunset time in order to get and display "minutes left until sunset"
timer = QtCore.QTimer(self)
time= QtCore.QTime.currentTime()
timer.timeout.connect(self.showlcd)
timer.timeout.connect(self.showlcd_2)
timer.start(1000)
self.showlcd()
def showlcd(self):
time = QtCore.QTime.currentTime()
current = time.toString('hh:mm')
self.ui.lcdNumber.display(current)
def showlcd_2(self):
time = QtCore.QTime.currentTime()
sunset = time.toString('18:30')
current_time =(time.hour,time.minute,time.second)
sunset_time = time(18,30,00)
TillSunset = sunset_time-current_time
minutesTillSunset=divmod(TillSunset.seconds, 60)
self.ui.lblTillSunset.setText("minutesTillSunset.%s" %minutesTillSunset)
self.ui.lcdNumber_2.display(sunset)
def showTimeTillSunset(self):
self.ui.lblTillSunset.display(TillSunset)
pixmapTwo = QPixmap(os.getcwd() + '/sunset.jpg')
lblSunsetPic.setPixmap(pixmapTwo)
lblSunsetPic.show
The error occurs because the instantiated
QTime
objecttime
itself cannot be called. In the following statementsunset_time = time(18,30,00)
you call an instantiated Qtime object with three arguments: 18,30,00. But you can only use this on the constructor, what you do correctly with:sunset_time = QtCore.QTime(18, 30, 00)
So to answer your question, the error occurs because you call an instantiated object instead of its constructor. Check out the other answer for tips on your solution in general :)