PyQT4 QTime对象不可调用



;时间=时间(18,30,00(";行产生一个"QTime"对象不可调用错误。。。。我做错了什么?。。我的应用程序应该获得并显示当前时间,然后设置日落时间,然后从日落时间中减去当前时间;离日落还有几分钟";

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

我不理解执行以下操作的逻辑:

time = QtCore.QTime.currentTime()
# ...
sunset_time = time(18,30,00)

正确的做法是从日落开始创建QTime;减去";它,相当于知道通过secsTo方法可以获得的QTimes之间的时间:

def showlcd_2():
current_time = QtCore.QTime.currentTime()
sunset_time = QtCore.QTime(18, 30, 00)
m, s = divmod(current_time.secsTo(sunset_time), 60)
self.ui.lblTillSunset.setText(("minutesTillSunset.%s" % m)
self.ui.lcdNumber_2.display(sunset_time.toString("hh:mm"))

由于无法调用实例化的QTime对象time本身,因此发生错误。在下面的语句sunset_time = time(18,30,00)中,您使用三个参数调用一个实例化的Qtime对象:18,30,00。但是你只能在构造函数上使用它,你可以正确地使用:sunset_time = QtCore.QTime(18, 30, 00)
所以为了回答你的问题,错误的发生是因为你调用了一个实例化的对象而不是它的构造函数。查看其他答案,了解有关解决方案的一般提示:(

最新更新