'timer in kivy of minute and second
I am trying to create a timer in kivy for a label but whenever executing the code, getting the error TypeError: unsupported operand type(s) for -=: 'str' and 'int' here is the code for the same main file:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.properties import ObjectProperty
Builder.load_file('pythonitcal CSS.kv')
class MyLayout(Widget):
def start_timer(self):
startTime=self.ids.timeInput.text
# self.ids.time.text = startTime
t=startTime
t-=1
i=59
while t>=0:
while i>=0:
self.ids.time.text = t
i-=1
t-=1
i=59
class Labels(App):
def build(self):
return MyLayout()
if __name__ == '__main__':
Labels().run()
kivy file:
#:kivy 2.1.0
#:import utils kivy.utils
<Label>
size_hint: (0.2,0.2)
font_size: 32
canvas.before:
Color:
rgba:utils.get_color_from_hex('#ef944a')
Rectangle:
pos: self.pos
size: self.size
<MyLayout>
canvas.before:
Color:
rgba:utils.get_color_from_hex('#429682')
Rectangle:
size: self.size
pos: self.pos
BoxLayout:
orientation:'vertical'
size:root.width,root.height
padding: 15
Label:
id:time
text:'Time left: '
size_hint:(1,0.2)
TextInput:
id:timeInput
multiline: False
Button:
text:'Start'
on_press: root.start_timer()
you can add animation in the label part if it is needed, or even simple-looking timer can do the trick. thank you in advance
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
