1 year ago

#353980

test-img

Anas

Countdown in Kivy

I am creating an application which will display appointment times from a database.

I want to create a countdown timer which displays the amount of time left until the next appointment in hours, minutes and seconds. Any idea how to implement this with Kivy?

After some research, I managed to add a stopwatch on my interface which counts seconds, but I have no idea how to compare the current time to the appointment time, and then display the remaining time.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.properties import StringProperty, NumericProperty

class Sections(BoxLayout):
    label_text = StringProperty()

    number = NumericProperty()

    def __init__(self, **kwargs):
        super(Sections, self).__init__(**kwargs)

        Clock.schedule_interval(self.increment_time, .1)

        self.increment_time(0)

    
    def increment_time(self, interval):
        self.number -= .1

    def start(self):
        Clock.unschedule(self.increment_time)
        Clock.schedule_interval(self.increment_time, .1)

   
    def stop(self):
        Clock.unschedule(self.increment_time)


kv = Builder.load_file('main text')

class AlHuda(App):

    def build(self):
        return kv


    def on_start(self):
        pass



AlHuda().run()
<Sections>:

    orientation: 'vertical'
    size_hint_y: None
    height: 800

    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'Timer'
    BoxLayout:
        Label:

            text: str(round(root.number))
            text_size: self.size
            halign: 'center'
            valign: 'middle'
    
    



python

kivy

kivy-language

countdown

kivymd

0 Answers

Your Answer

Accepted video resources