Я хочу, чтобы моя программа сравнивала время, сохраненное в кнопке, с текущим временем. Кнопка должна изменить желтый цвет, если «рано», зеленый, если «вовремя», и красный, если «поздно». Когда я запускаю программу, я получаю эту ошибку:
honey = float(self.streak_button.id)
AttributeError: 'MainApp' object has no attribute 'streak_button'
Это мой код:
class MainApp(App):
def build(self): # build() returns an instance
self.store = JsonStore("streak.json") # file that stores the streaks:
Clock.schedule_interval(self.check_streak, 1/30.)
return presentation
def check_streak(self, dt):
honey = float(self.streak_button.id)
#print(f"\tdelta={honey}")
# used to give 30 minute grace period
delay = honey + 1800
check = False
if honey > time.time() and honey < delay:
check = True
if honey > time.time():
self.streak_button.color = 0,1,0
if check == True:
self.streak_button.color = 0,0,1
if honey < time.time():
self.streak_button.color = 1,0,0
def display_btn(self):
# display the names of the streaks in a list on PageTwo
with open("streak.json", "r") as read_file:
data = json.load(read_file)
for value in data.values():
if value['delta'] is not None:
print(f"action={value['action']}, delta={value['delta']}")
self.streak_button = StreakButton(id=str(value['delta']), text=value['action'],
on_press=self.third_screen)
self.root.screen_two.ids.streak_zone.add_widget(self.streak_button)