python - PyQt: Label not showing correct number of length -
i making quiz application in pyqt4, there 3 main generators:
incorrect
, correct
, timeout
.
all answers connecting scorecheck function:
def scorecheck(self, sendercheck): if ( sendercheck == self.answ ) or ( sendercheck == self.answ1 ) or ( sendercheck == self.answ5 ) or ( sendercheck == self.answ7 ) or ( sendercheck == self.answ8 ) or ( sendercheck == self.answ10 ): self.wronganswers.append(1) elif ( sendercheck == self.answ2 ) or ( sendercheck == self.answ4 ) or ( sendercheck == self.answ9 ): self.correctanswers.append(1) elif sendercheck == self.tmr3: self.timeouts.append(1) print "worked" print len(self.timeouts) else: pass self.wronganswerlabel = qtgui.qlabel(str(len(self.wronganswers)), self) self.wronganswerlabel.setgeometry(220, 40, 200, 200) self.wronganswerlabel.setobjectname('wronganswercount') self.wronganswerlabel.setstylesheet("#wronganswercount { font-size: 31pt; color: white; border: none; }") self.timeoutlabel = qtgui.qlabel(str(len(self.timeouts)), self) self.timeoutlabel.setgeometry(480, 80, 200, 200) self.timeoutlabel.setobjectname('timeoutlabel') self.timeoutlabel.setstylesheet("#timeoutlabel { font-size: 31pt; color: white; border: none; }") self.correctanswerlabel = qtgui.qlabel(str(len(self.correctanswers)), self) self.correctanswerlabel.setgeometry(1050, 40, 200, 200) self.correctanswerlabel.setobjectname('correctanswercount') self.correctanswerlabel.setstylesheet("#correctanswercount { font-size: 31pt; color: white; border: none }") summary = len(self.correctanswers) + 100 - len(self.wronganswers) - len(self.timeouts) % 10 if summary < 0: while summary < 0: summary += 1 self.summarylabel = qtgui.qlabel(str(summary), self) self.summarylabel.setgeometry(850, 222, 200, 200) self.summarylabel.setobjectname('summary') self.summarylabel.setstylesheet("#summary { font-size: 40pt; color : white; border: none }")
when loss count reach 3, activate gameover function, labels shown.
wronganswerslabel , correctanswerslabel showing normally, timeoutlabel shown 0.
but added print len(timeouts)
in general parts of scorecheck , gameover function , results equal 1.
i tried this: self.timeouts.append(1)
self.timeouts.append(1)
strangely shown 2 in label.
i tried multiprocessing scorecheck function thought performance problem, nothing did update.
what may problem be? why timeoutlabel showing 0 , others showing proper numbers? because performance or incorrect input?
i have fixed problem:
sequence of functions:
2 3 2 3 1 2 3 4 5
2
on top of label defined.
3
on bottom of label defined.
1
sendercheck statement of timeout. (important)
4
on top of label shown.
5
under label shown.
where timer defined:
self.tmr3 = qtcore.qtimer(self) self.tmr3.setsingleshot(true) self.tmr3.timeout.connect(partial(self.timeout, self.tmr3)) # connects timeout first, thats why sequence going wrong. self.tmr3.timeout.connect(partial(self.scorecheck, self.tmr3)) self.tmr3.timeout.connect(partial(self.checkifout, self.tmr3))
fixed adding scorecheck @ first timeout signal:
self.tmr3 = qtcore.qtimer(self) self.tmr3.setsingleshot(true) self.tmr3.timeout.connect(partial(self.scorecheck, self.tmr3)) self.tmr3.timeout.connect(partial(self.timeout, self.tmr3)) self.tmr3.timeout.connect(partial(self.checkifout, self.tmr3))
Comments
Post a Comment