I am making a project in which whenever I stop the stopwatch, it updates the time into a Listbox. It can be updated in the self.m listbox. However it cannot be updated into topscoreslistbox.
In the printFunctionStop function, i call back the Stop method in a class. However i do not know how to call the TopscoresStop in the main function.
The Stop method and TopscoresStop method do the same thing. However the different thing is one is in the class and one is in the main function.
So how do i call the method TopscoresStop in the main function in printFunctionStop anyone knows?
class StopWatch(Frame):
def Stop(self):
""" Stop the stopwatch, ignore if stopped. """
tempo = self._elapsedtime - self.lapmod2
if self._running:
self.after_cancel(self._timer)
self._elapsedtime = time.time() - self._start
self._setTime(self._elapsedtime)
self._running = 0
if len(self.laps) == 3:
return
self.laps.append(self._setLapTime(tempo))
self.m.insert(END, (str(self.one.get()) , "%.2f" % self._elapsedtime))
self.m.yview_moveto(1)
def main():
def Topscores():
toplevel() = Toplevel()
toplevel.title("Top Scores")
topscoreslistbox = Listbox(toplevel, selectmode=EXTENDED, height=3, width=20, font=("Helvetica", 26))
topscoreslistbox.pack(side=RIGHT, fill=BOTH, expand=1, pady=5, padx=2)
first = Label(toplevel, text=("1st"), font=("Algerian", 30))
first.pack(side=TOP)
second = Label(toplevel, text=("2nd"), font=("Algerian", 30))
second.pack(side=TOP)
third = Label(toplevel, text=("3rd"), font=("Algerian", 30))
third.pack(side=TOP)
def TopscoresStop():
tempo = sw._elapsedtime - sw.lapmod2
if sw._running:
sw.after_cancel(sw._timer)
sw._elapsedtime = time.time() - sw._start
sw._setTime(sw._elapsedtime)
sw._running = 0
if len(sw.laps) == 3:
return
sw.laps.append(sw._setLapTime(tempo))
topscoreslistbox.insert(END, (str(sw.one.get()) , "%.2f" % sw._elapsedtime))
topscoreslistbox.yview_moveto(1)
def printFunctionStop(channel):
sw.event_generate("<<Stop>>", when = "tail")
GPIO.add_event_detect(16, GPIO.FALLING, callback = printFunctionStop, bouncetime=300)
sw.bind("<<Stop>>", lambda event:sw.Stop())