JennilynDagansina / EEE-EXAM

Project-Based Exam for Programming
2 stars 3 forks source link

Update README.md #2

Open VincentGreggPamor opened 2 years ago

VincentGreggPamor commented 2 years ago

Python code for Stopwatch

Rheelmi commented 2 years ago

Good Evening guys eto young code para sa update para mag update atong timer every seconds😊

def update():

update seconds with (addition) compound assignment operator

global hours, minutes, seconds
seconds += 1
if seconds == 60:
    minutes += 1
    seconds = 0
if minutes == 60:
    hours += 1
    minutes = 0
# format time to include leading zeros
hours_string = f'{hours}' if hours > 9 else f'0{hours}'
minutes_string = f'{minutes}' if minutes > 9 else f'0{minutes}'
seconds_string = f'{seconds}' if seconds > 9 else f'0{seconds}'
# update timer every 1000ms to 1 sec
stopwatch_label.config(text=hours_string + ':' + minutes_string + ':' + seconds_string)
# after each seconds make an uosate on the timer
# use update_time variable to cancel or pause the time using after_cancel
global update_time
update_time = stopwatch_label.after(1000, update)