Timer defined in code not firing

Why doesn’t this fire :

class Form1(Form1Template):
  def __init__(self, **properties):
    self.init_components(**properties)

  def tick(self, **event_args):
    print("in tick")    

  def form_show(self, **event_args):
    self.tmr = Timer(interval=0)
    self.tmr.set_event_handler("tick", self.tick)
    self.tmr.interval = 5

Clone here :
https://anvil.works/build#clone:TY7SRW73GRV6R6MZ=PAOBLA4MHXTJ53RIOLXE62AF

1 Like

oooh very niche - docs say:

The tick event only fires while the timer is on the page

To be on the page it must have a parent

self.tmr.parent returns None

So doing the following works:

self.add_component(self.tmr)

I wonder if this has always been the case and has never caused anyone a problem before…

1 Like

Well spotted, sir!

2 posts were split to a new topic: Timer not firing