Frage

self.date = QtCore.QDate.currentDate() 
self.time = QtCore.QTime.currentTime()
self.updateTime = QtCore.QString(self.time.toString("hh:mm:ss AP"))
if ((self.time.second() % 2) == 0):
    self.updateTime[2]= ' '

self.label.setText(self.updateTime)

Error: TypeError: file line 54: 'QString' object does not support item assignment

iam getting this error in if loop, is there any solution? iam new to python any help appreciated....

thank you

War es hilfreich?

Lösung

Your problem is that you cannot change the the QString by item assignment (a[2] = ' '); you get a TypeError whenever you try to do something to an object that isn't allowed. You have to create a new string and assign it to the variable. So, replace the line

self.updateTime[2]= ' '

with the following

self.updateTime = self.updateTime[:2] + ' ' +self.updateTime[3:]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top