There was a problem, the text on the application screen is not updated. Implemented something like a countdown, but the graphical interface does not display changes.
Used StringProperty, tried through self.ids ...
Content of python file:
# encoding:utf-8 # memorizer main file from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.clock import Clock from kivy.uix.screenmanager import ScreenManager from kivy.uix.screenmanager import Screen from kivy.properties import BooleanProperty from kivy.properties import StringProperty import random # count = 10 count = 3 class MemoScreen(Screen): scr = BooleanProperty(False) time_var = StringProperty('Initial') def __init__(self, **kwargs): super(Screen, self).__init__(**kwargs) def number(self): return random.randint(100000, 999999) def time_left(self, *args, **kwargs): global count self.time_var = str(count) print('time_var: {}'.format(self.time_var)) if count: count -= 1 else: self.time_var = 'Time is over!' Clock.unschedule(self.time_left) print('time_var: {}'.format(self.time_var)) # return None class CheckScreen(Screen): pass class MemorizerApp(App): def build(self): self.title = 'Memorizer' sm = ScreenManager() sm.add_widget(MemoScreen(name='MemoScr')) sm.add_widget(CheckScreen(name='CheckScr')) memo = MemoScreen() check = CheckScreen() Clock.schedule_interval(memo.time_left, 1.0) return sm if __name__ == '__main__': MemorizerApp().run() Content of the .kv file
# :kivy 1.0.9 <MemoScreen>: BoxLayout: orientation: 'vertical' Label: font_size: 70 size_hint_y: 30 center_x: root.width / 2 text: "Memorize this number:" Label: id: number font_size: 100 size_hint_y: 40 center_x: root.width / 2 text: str(root.number()) Label: id: time_left font_size: 70 size_hint_y: 30 center_x: root.width / 2 # text: root.time_left() text: str(root.time_var) # Button: # id: button1 # text: 'Go to CheckScreen' # on_press: # root.manager.transition.direction = 'left' # root.manager.current = 'CheckScr' <CheckScreen>: BoxLayout: orientation: 'vertical' Label: id: check font_size: 70 size_hint_y: 30 center_x: root.width / 2 text: 'Input memorized number!' Label: id: input_field font_size: 100 size_hint_y: 30 Label: id: time_left_to_fill font_size: 70 size_hint_y: 20 center_x: root.width / 2 Button: id: btn_submit size_hint_y: 20 center_x: root.width / 2 Button: id: button2 text: 'Go to CheckScreen' on_press: root.manager.transition.direction = 'right' root.manager.current = 'MemoScr' Mac OS X Mojave, Python 3.7.0 (v3.7.0: 1bf9cc5093, Jun 26 2018, 23:26:24) [Clang 6.0 (clang-600.0.57)] on darwin, Kivy 1.10.1
Thanks in advance for help of any kind.