Question: This is my Clock class set methods. def increaseDay ( self ) : if self.day < self.months [ self . month - 1 ] :

This is my Clock class set methods.
def increaseDay(self):
if self.day < self.months[self.month -1]:
self.day +=1
else:
self.day =1
if self.month <12:
self.month +=1
else:
self.month =1
self.year +=1
if self.leap_year(self.year):
self.months[1]=29
else:
self.months[1]=28
def decreaseDay(self):
if self.day >1:
self.day -=1
else:
if self.month >1:
self.month -=1
self.day = self.months[self.month -1]
else:
self.year -=1
self.month =12
self.day =31
def increaseSecond(self):
self.sec +=1
if self.sec ==60:
self.sec =0
self.min +=1
if self.min ==60:
self.min =0
self.hr +=1
if self.hr ==24:
self.hr =0
self.increaseDay()
def decreaseSecond(self):
self.sec -=1
if self.sec ==-1:
self.sec =59
self.min -=1
if self.min ==-1:
self.min =59
self.hr -=1
if self.hr ==-1:
self.hr =23
self.decreaseDay()
This below code needs to be inherited from Clock class
import tkinter as tk
from datetime import datetime
class Clock():
def __init__(self):
self.time = datetime.now()
def __str__(self):
return self.time.strftime('%m/%d/%Y %I:%M:%S %p')
def set_clock(self, month, day, year, hour, minute, second):
try:
self.time = datetime(year, month, day, hour, minute, second)
return True
except ValueError:
return False
def increase_day(self):
self.time += timedelta(days=1)
def decrease_day(self):
self.time -= timedelta(days=1)
def increase_second(self):
self.time += timedelta(seconds=1)
def decrease_second(self):
self.time -= timedelta(seconds=1)
def set_time():
try:
selected_time = datetime(int(year_list.get(tk.ACTIVE)), months.index(month_list.get(tk.ACTIVE))+1, int(day_list.get(tk.ACTIVE)),
int(hour_list.get(tk.ACTIVE)), int(minute_list.get(tk.ACTIVE)), int(second_list.get(tk.ACTIVE)))
if clock.set_clock(selected_time.month, selected_time.day, selected_time.year,
selected_time.hour, selected_time.minute, selected_time.second):
time_label.config(text=clock.__str__())
else:
time_label.config(text

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!