tkinter - How to call back methods in python? -
i making project in whenever stop stopwatch, updates time listbox. can updated in self.m listbox
. cannot updated topscoreslistbox
.
in printfunctionstop
function, call stop method in class. not know how call topscoresstop
in main function.
the stop
method , topscoresstop
method same thing. different thing 1 in class , 1 in main function.
so how call method topscoresstop
in main function in printfunctionstop
knows?
class stopwatch(frame): def stop(self): """ stop 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())
have tried passing function argument printfunctionstop
?
sorry, can't make comments yet.
e.g.
def a(): print('hi') def b(func): func() def main(): b(a) main()
the main should print 'hi'
Comments
Post a Comment