I am having an issue in Kivy with the Clock library. I am attempting to create a countdown timer for a game. The default time that I have set for the timer is 10:00 minutes. Each second, I want to update a label in Kivy that displays the time, but the clock seems to get frozen at 09:59 minutes, and will stops updating. Here is what I've done so far.
class AddNumbers(Screen):
def __init__(self, **kwargs):
super(AddNumbers, self).__init__(**kwargs)
self.minutes = 10
self.seconds = 0
In my first class, I add attributes for minutes and seconds so that the default minutes will be set to 10, and the default seconds will be set to 0.
Next I add the AddNumbers class attributes and methods to my main app class.
class MinuteMathApp(App, AddNumbers):
In my main app class I add a method called "timer" that should subtract -1 from self.seconds each time this function is called. Once self.seconds is == to -1, self.minutes will decline by 1, self.seconds should increase by += 60 so that it can restart at 59 seconds, and begin counting down again. If minutes and seconds == 0, then I will freeze the time at 00:00. I create a datetime.timedelta object in which the minutes are set equal to self.minutes, and the seconds are set equal to self.seconds. I then update my kivy label with the string form of the time.
def timer(self, *args):
self.seconds - 1
if self.seconds == -1:
self.seconds += 60
self.minutes -= 1
if self.minutes == 0 and self.seconds == 0:
self.minutes = 0
self.seconds = 0
self.time = datetime.timedelta(minutes=self.minutes, seconds=self.seconds)
self.root.ids.time.text = str(self.time)
Lastly, I have a function called addnums, which is binded to a Button in kivy. When the user presses this Button they will be asked a series of math questions and this is where the timer should start. I schedule the timer function to run once per seconds with the Clock.schedule_interval function. Since I have self.seconds - 1 in my function, my thought process was that the function would subtract 1 second EACH time the function was called with the Clock.schedule_interval function. However, my issue is that the time stays frozen at 10:00 and does not change on my kivy label.
def addnums(self):
Clock.schedule_interval(self.timer, 1)
Here is the part of my .kv code that corresponds with this function being called.
Button:
text: 'Get Question'
id: easy_addition_next_question_button
background_normal: 'navy.png'
on_press: app.addnums()
And here is my label in the .kv file that should be updated:
Label:
id: time
text: 'Time: '
Here is a picture of my application with the time frozen just for a visual representation of what i'm attempting to accomplish:

As you can see, the time is frozen at 0:09:59, and not updating as I expected.
I apologize in advance for the long question. I feel as if it is important to be as detailed as possible so that there is simply no confusion. The hardest questions for me to answer on this site are the ones that lack any form of detail, and it's difficult to structure a question accurately without some form of detail.