Timer component questions

In the code tab of a form, how do you use the Timer function? Also, is its interval in milliseconds, seconds, minutes, etc?

Timer is actually a (Anvil-supplied) class, not a function. When called as a function, it returns an object. This object behaves as a timer. You can read about it here.

1 Like

Be sure to check out this post

I made this timer project but it doesn’t work for some reason. Please, help. Link to the project is here:https://anvil.works/build#app:JQIE3PPJS455B6A3

Hey @choprasahil.sc,

We’re glad to see you getting to grips with Anvil, but you’ve now posted four separate topics in this forum, in a very short period of time, asking about the same thing. This isn’t going to get you answers any faster, but it does clutter up the forum for everyone else! I’ve merged two questions into this thread and deleted a spurious Show&Tell post.

If you want to get help, please make it easier for people to work out the answer for you! You might want to look at our guide to how to ask a good question, including an illustrated step-by-step example of how to make a question easier to answer!

I hope this helps you ask the right question and find a solution to your problem soon!

1 Like

I opened it but it’s completely emty

1 Like

Sorry I meant the entire thread rather than the specific post.

In that thread I mention that a timer must be on screen in order to fire.
So if you add a timer in code you also have to add the timer component to a parent like

T = Timer()
self.add_component(T)

The interval is in seconds.

I’m not sure the clone link you’ve shared above is valid.

I’m sorry I didn’t know how to properly send link I think this will be right one https://anvil.works/build#clone:JQIE3PPJS455B6A3=ZSTUWOWKDQJBMOKLCHLPLOU7

You seem to have confused interval with total time.
interval is how often you raise a tick event
there is no way to set the total time of a timer.
You just set the interval to 0 when you’re done…

1 Like

this may sound really dumb but I can’t see your whole message. It just turns into dots. How do i see it?

That was the whole message :upside_down_face:

If you need a bit more here’s some pseudo code

self.total_time = 60 # num seconds from code 
self.timer.interval = 1 # the timer will tick every 1 second
# make sure you’ve set the timer tick event in design view

def timer_tick(self, **event_args):
  if self.total_time <= 0:
    self.timer.interval = 0
  print(self.total_time)
  self.total_time -= 1

1 Like