посмотрите (плз) че да как, какие есть огрехи.
py файл
# -*- coding: utf-8 -*- # data: 2019, 12, 29 # ''' # Python 3.6.8 (default, Oct 7 2019, 12:59:55) # [GCC 8.3.0] on linux # # kivy v1.11.1 DATE 20190620 # ''' # ''' # screenshots: # ----- # HTML # <a href="http://i.imgur.com/R0TN8Ir.png"> # <img src="http://imgur.com/R0TN8Irl.png" /> # </a> # ----- # BBCode # [url=http://i.imgur.com/R0TN8Ir.png] # [img]http://imgur.com/R0TN8Irl.png[/img] # [/url] # ''' import calendar import datetime import time from kivy.app import App from kivy.lang import Builder from kivy.uix.stacklayout import StackLayout Builder.load_file("KivyDataTimeInputWidget1.kv") initial_year_month = None selected_year_month_day = None class KivyDataTimeInputWidget(StackLayout): def __init__(self): super().__init__() global initial_year_month if type(initial_year_month) == type(None): self.this_day = list( datetime.date.today().timetuple()[:2]) else: self.this_day = initial_year_month self.btn_arr = ( self.ids.btn00, self.ids.btn01, self.ids.btn02, self.ids.btn03, self.ids.btn04, self.ids.btn05, self.ids.btn06, self.ids.btn07, self.ids.btn08, self.ids.btn09, self.ids.btn10, self.ids.btn11, self.ids.btn12, self.ids.btn13, self.ids.btn14, self.ids.btn15, self.ids.btn16, self.ids.btn17, self.ids.btn18, self.ids.btn19, self.ids.btn20, self.ids.btn21, self.ids.btn22, self.ids.btn23, self.ids.btn24, self.ids.btn25, self.ids.btn26, self.ids.btn27, self.ids.btn28, self.ids.btn29, self.ids.btn30, self.ids.btn31, self.ids.btn32, self.ids.btn33, self.ids.btn34, self.ids.btn35, self.ids.btn36, self.ids.btn37, self.ids.btn38, self.ids.btn39, self.ids.btn40, self.ids.btn41) self.write_days_in_the_button_table() self.write_month_to_label() def write_days_in_the_button_table(self): tmp = self.calculate_days_table_list() for i in range(42): if tmp[i] == 0: self.btn_arr[i].text = "" else: self.btn_arr[i].text = str( tmp[i]) def write_month_to_label(self): tmp = time.strftime("%B", time.gmtime( calendar.timegm( self.this_day + [1, 0, 0, 0]))) self.ids.year_month.text = "{} - {}\n".format( tmp, str(self.this_day[0])) def calculate_next_or_prev_month(self, flag): """ next_or_previous_month(True) -> [2019, 12] if next True or previous if False relative to the current month widget :param flag: bool :return: list() """ tmp = calendar.timegm(self.this_day + [1, 0, 0, 0]) if flag: tmp = tmp + calendar.monthrange( self.this_day[0], self.this_day[1])[1] * 86400 else: tmp = tmp - 1 return list(time.gmtime(tmp))[:2] def on_release_button_prev(self): self.this_day = self.calculate_next_or_prev_month(0) self.write_month_to_label() self.write_days_in_the_button_table() def on_release_button_next(self): self.this_day = self.calculate_next_or_prev_month(1) self.write_month_to_label() self.write_days_in_the_button_table() @staticmethod def on_release_button_close(): main.stop() def on_release_button(self, instance): try: global selected_year_month_day selected_year_month_day = \ self.this_day + [int(instance.text)] self.on_release_button_close() except ValueError: pass def calculate_days_table_list(self): tmp = [*calendar.Calendar().itermonthdays( self.this_day[0], self.this_day[1])] if len(tmp) < 42: tmp = tmp + [0] * ( 42 - len(tmp)) return tmp class Realization(KivyDataTimeInputWidget): ''' for example change the text color of all day buttonst class Test(Realization): def __init__(self): super().__init__() self.theme() def theme(self): for i in self.btn_arr: i.color = [255, 255, 45, 1] i.text = "*" + i.text main = MainApp(Test) main.run() ''' def __init__(self): super().__init__() class MainApp(App): def __init__(self, realization): super().__init__() self.realization = realization def build(self): return self.realization() main = MainApp(Realization) if __name__ == '__main__': main.run() # test result print(selected_year_month_day)
исправленный файл в 3 посте