main.py from kivy.app import App from kivy.lang import Builder from kivy.uix.label import Label from time import strftime from functools import partial import time from kivy.clock import Clock from kivy.uix.popup import Popup sec = 0 mi = 0 hr = 0 class Clock_Date_Label(Label): def show_time_date(self, *args): self.text = str(strftime("Date: %d/%b/%Y\nTime: %H:%M:%S %p")) class Timer_label(Label): def show_timer(self, *args): global mi global hr global sec ii = 1 if App.get_running_app().root.ids.StopWatch_ToggleButton_id.text == "Pause": ii -= 1 sec += 1 if sec == 59: sec = 0 mi += 1 if mi == 60: mi = 0 hr += 1 self.text = str(str(hr) + ':' + str(mi) + ':' + str(sec)) def reset(self): global mi global hr global sec sec = 0 hr = 0 mi = 0 self.text = '00:00:00' class Timer_Label(Label): def start_timer(self,sec,mi,hr,*args): if App.get_running_app().root.ids.timer_ToggleButton_id.text == "Pause": if sec !=0: sec -= 1 if sec == 00 : sec = 59 mi -= 1 if mi == 0 : mi = 59 hr -= 1 self.text = str(str(hr) + ':' + str(mi) + ':' + str(sec)) Clock.schedule_once(partial(self.start_timer, sec, mi, hr), 1) def restart_timer(self,sec,mi,hr,*args): #Clock.schedule_once(partial(self.start_timer, 0, 0, 0)) Clock.schedule_once(partial(self.start_timer, sec, mi, hr),.00001) print(sec,mi,hr) class Set_Timer(Popup): pass class KivyApp(App): def build(self): return Builder.load_file("main.kv") def on_start(self): #print(self.root.ids.Clock_Date_Label_id.show_time_date) Clock.schedule_interval(self.root.ids.Timer_label_id.show_timer, .5) Clock.schedule_interval(self.root.ids.Clock_Date_Label_id.show_time_date, .5) def open_set_timer_popup(self): Set_Timer().open() KivyApp().run() main.kv BoxLayout: timer_Seconds_reset: '' timer_Minutes_reset: '' timer_Hours_reset:'' orientation: 'vertical' TabbedPanel: do_default_tab: False TabbedPanelItem: background_color: .3,.8,.1,1 text: 'Clock' BoxLayout: canvas.before: Color: rgba: .3,.8,.1,1 Rectangle: pos: self.pos size: self.size Clock_Date_Label: id: Clock_Date_Label_id color:0,0,1,1 font_size: .1*self.width TabbedPanelItem: background_color:1,1,0,1 text: 'StopWatch' BoxLayout: orientation: 'vertical' canvas.before: Color: rgba: 1,1,0,1 Rectangle: pos: self.pos size: self.size Timer_label: id: Timer_label_id font_size: .1*self.width canvas.before: Color: rgba: 1,1,0,1 Rectangle: pos: self.pos size: self.size BoxLayout: ToggleButton: id: StopWatch_ToggleButton_id text: "Start" on_press: self.text ="start" if(StopWatch_ToggleButton_id.state == "normal") else("Pause") Button: id:ok text: "Reset" on_press: app.root.ids.Timer_label_id.reset() TabbedPanelItem: background_color:0.5,0,1,1 text: 'Timer' BoxLayout: orientation: 'vertical' canvas.before: Color: rgba: 0.5,0,1,1 Rectangle: pos: self.pos size: self.size Timer_Label: size_hint_y: 2 id: Timer_Label_id ToggleButton: text: 'Pause' if self.state == 'normal' else 'Start' id: timer_ToggleButton_id Button: text: 'Restart' on_press: app.root.ids.Timer_Label_id.restart_timer(int(root.timer_Seconds_reset),int(root.timer_Minutes_reset),int(root.timer_Hours_reset)) Button: text: 'Set Timer' on_press: app.open_set_timer_popup() : title: 'Set the Timer' size_hint:.7,.3 id: Set_Timer_popup BoxLayout: orientation: 'vertical' BoxLayout: TextInput: hint_text: 'hr' font_size:.50* self.width text: app.root.timer_Hours_reset id: hr_id focuse: True if len(self.text) <= 2 else False TextInput: hint_text: 'min' font_size:.50* self.width text: app.root.timer_Minutes_reset id: min_id TextInput: hint_text: 'sec' font_size:.50* self.width text: app.root.timer_Seconds_reset id: sec_id BoxLayout: Button: text: 'Set' on_press: app.root.ids.Timer_Label_id.start_timer(int(sec_id.text),int(min_id.text),int(hr_id.text)) app.root.timer_Seconds_reset =sec_id.text app.root.timer_Minutes_reset =min_id.text app.root.timer_Hours_reset = hr_id.text #on_release: app.root.ids.Timer_Label_id.timer_start() #on_press:print(type(int(sec_id.text))) on_press: Set_Timer_popup.dismiss() Button: text: 'Clear' on_press: hr_id.text = '' on_press: min_id.text = '' on_press: sec_id.text = ''