title: Showing tasks only after new program launch. kivy
body: <p>Good evening. I'm learning kivy and trying to make something like &quot;microsoft to do&quot;. But I have a problem. Now I'm doing an adding task function. The main idea of it:</p>
  <ol>
  <li>When I click &quot;add task&quot;(button with plus icon) button, my screen changes on &quot;AddingNewTaskScreen&quot;.</li>
  <li>In AddingNewTaskScreen class I created a function &quot;&quot;addTask that takes text from TextInput and add it in text file. Then it changes this screen on &quot;MainMenuScreen&quot;</li>
  <li>In MainMenuScreen class(it is first screen), in constructor i call a &quot;taskRead&quot; function that takes text from text file and write it in array. Then it adds elements of arrays in MDList and after it, it adds this MDList to ScrollView.</li>
  </ol>
  <p>And it works, but it takes shows me tasks after new programm launch. For example: I add the task and the &quot;MainMenuScreen&quot; doesn't show me anything. But when I restart my programm, everything are in ScrollView. If you have any ideas how it can be fixed, please tell me, I wold really apreciate it. Thank you for advance.</p>
  <p>main.py</p>
  <pre><code>from kivy.uix.button import Button
  from kivy.uix.screenmanager import Screen, ScreenManager
  from kivy.core.window import Window
  from kivy.uix.widget import Widget
  from kivymd.app import MDApp
  from kivymd.uix.list import OneLineListItem, MDList
  from kivy.properties import ObjectProperty
  from kivy.uix.scrollview import ScrollView
  from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
  
  class MainMenuScreen(Screen):
      listBox = ObjectProperty()
      theme_changer = ObjectProperty()
      search_task = ObjectProperty()
      all_tasks = ObjectProperty()
      important_tasks = ObjectProperty()
      create_list = ObjectProperty()
      completed_tasks = ObjectProperty()
      list_name = ObjectProperty()
      sort = ObjectProperty()
      rename = ObjectProperty()
      add_button = ObjectProperty()
      scroll = ScrollView()
      list_view = MDList()
  
      def __init__(self, **kw):
          super().__init__(**kw)
          self.taskRead()
  
      def taskRead(self):
  
          sv = open('tasks.txt', 'r', encoding='utf-8')
          arr = sv.read().split('\n')
          sv.close()
          for i in range(len(arr)):
              self.list_view.add_widget(OneLineListItem(text=arr[i], on_press=self.scr))
              self.add_widget(MDList())
          self.scroll.add_widget(self.list_view)
          self.listBox.add_widget(self.scroll)
  
      def scr(self, value):
          self.manager.transition = FadeTransition()
          self.manager.current = 'goodbye_screen'
  
  
  class ToDoListApp(MDApp):
  
      def __init__(self, **kw):
          super().__init__(**kw)
  
      def build(self):
          self.theme_cls.theme_style = &quot;Dark&quot;
          Window.size = (1300, 700)
          sm = ScreenManager()
          sm.add_widget(MainMenuScreen(name='main_menu_screen'))
          sm.add_widget(ImportantOrCompletedTaskCheckScreen(name='goodbye_screen'))
          sm.add_widget(AddingNewTaskScreen(name='adding_newTask_screen'))
          return sm
  
  
  class AddingNewTaskScreen(Screen):
      taskToTxt = ObjectProperty()
      addTaskButton = ObjectProperty()
  
      def __init__(self, **kw):
          super().__init__(**kw)
  
      def addTask(self):
          task_text = str(self.taskToTxt.text)
          sv = open('tasks.txt', 'a', encoding='utf-8')
          sv.writelines(str(task_text) + '\n')
          sv.close()
          ToDoListApp.get_running_app().root.current = &quot;main_menu_screen&quot;
  
  
  # Class for another problem
  class ImportantOrCompletedTaskCheckScreen(Screen):
      pass
  
  
  if __name__ == '__main__':
      ToDoListApp().run()
  
  
  </code></pre>
  <p>todolist.kv</p>
  <pre><code>&lt;MainMenuScreen@Screen&gt;:
      listBox:listBox
      rename:rename
      search_task:search_task
      theme_changer:theme_changer
      all_tasks:all_tasks
      important_tasks:important_tasks
      create_list:create_list
      completed_tasks:completed_tasks
      list_name:list_name
      sort:sort
      #add_button:add_button
      orientation: 'vertical'
  
      # right lateral panel
      BoxLayout:
          BoxLayout:
              size_hint: '0.3', '0.8'
              pos_hint: {'y': 0.17}
              orientation: 'vertical'
              GridLayout:
                  cols: 1
                  rows: 9
                  MDRoundFlatButton:
                      id: theme_changer
                      size_hint: 0.5, 0.3
                      text: 'Light theme'
                      line_color: 1,1,1,1
                      elevation_normal: 0
                      on_press: root.change_theme()
                  BoxLayout:
                      size_hint: 1, 0.5
                  MDRoundFlatButton:
                      size_hint: 1, 0.7
                      text: 'All tasks'
                      line_color: 1,1,1,1
                      id: all_tasks
                  BoxLayout:
                      size_hint: 1, 0.08
                  MDRoundFlatButton:
                      size_hint: 1, 0.7
                      text: 'Important'
                      line_color: 1,1,1,1
                      id: important_tasks
                  BoxLayout:
                      size_hint: 1, 0.08
                  MDRoundFlatButton:
                      size_hint: 1, 0.7
                      text: '+ Create \nlist'
                      line_color: 1,1,1,1
                      id: create_list
                  BoxLayout:
                      size_hint: 1, 0.08
                  MDRoundFlatButton:
                      size_hint: 1, 0.7
                      text: 'Completed \ntasks'
                      line_color: 1,1,1,1
                      id: completed_tasks
  
  
          # top panel
          BoxLayout:
              orientation: 'vertical'
              AnchorLayout:
                  anchor_y: 'top'
                  size_hint: 1, 0.05
                  GridLayout:
                      size_hint: 1, 0.05
                      cols: 4
                      rows: 1
                      Label:
                          text: 'Name'
                          size_hint: 0.5, 0.05
                          id: list_name
                      MDTextField:
                          id:search_task
                          halign: 'center'
                          valign: 'center'
                          hint_text: 'Search'
                          size_hint: 1, None
                          line_color_normal: 0.15,0.15,0.15
                      MDRectangleFlatButton:
                          id: rename
                          text: 'Rename'
                          line_color: 1,1,1,1
                      MDRectangleFlatButton:
                          text: 'Sort'
                          line_color: 1,1,1,1
                          id: sort
  
              # Center
  
              BoxLayout:
                  orientation: 'vertical'
                  size_hint: 0.1, 0.1
                  MDFloatingActionButton:
                      icon: &quot;plus&quot;
                      md_bg_color: 'black'
                      on_press: root.manager.current = 'adding_newTask_screen'
  
              BoxLayout:
                  orientation: 'vertical'
                  size_hint: 1,1
  
                  BoxLayout:
                      ScrollView:
                          line_color_normal: 1,1,0,1
                          id: listBox
  
  # Screen for another problem
  &lt;ImportantOrCompletedTaskCheckScreen@Screen&gt;:
      name: 'goodbye_screen'
      AnchorLayout:
          anchor_x: 'center'
          anchor_y: 'center'
          BoxLayout:
              orientation: 'vertical'
              size_hint: 0.5, 0.25
              GridLayout:
                  cols: 2
                  rows: 1
                  size_hint: 0.3, 0.25
                  pos_hint: {'x': 0.35}
                  MDSwitch:
                      size_hint: 0.3, 0.3
                      theme_text_color: &quot;Custom&quot;
                      text_color: 1, 1, 1, 1
                      line_color: 1, 1, 1, 1
                  Label:
                      text: 'Important'
              BoxLayout:
                  size_hint: 0, 0.5
              GridLayout:
                  cols: 2
                  rows: 1
                  size_hint: 0.3, 0.25
                  pos_hint: {'x': 0.35}
                  MDSwitch:
                      text: 'Important'
                      size_hint: 0.3, 0.3
                      theme_text_color: &quot;Custom&quot;
                      text_color: 1, 1, 1, 1
                      line_color: 1, 1, 1, 1
                  Label:
                      text: 'Completed'
              AnchorLayout:
                  anchor_x: 'center'
                  anchor_y: 'center'
                  MDRoundFlatButton:
                      text: 'Continue'
                      size_hint: 1, 0.5
                      theme_text_color: &quot;Custom&quot;
                      text_color: 1, 1, 1, 1
                      line_color: 1, 1, 1, 1
                      on_press: root.manager.current='main_menu_screen'
  
  
  &lt;AddingNewTaskScreen@Screen&gt;:
      taskToTxt:taskToTxt
  
      AnchorLayout:
          anchor_x: 'center'
          anchor_y: 'center'
          BoxLayout:
              orientation: 'vertical'
              size_hint: 0.5, 0.25
              MDTextField:
                  id: taskToTxt
                  hint_text: 'Name of new task'
                  color: 'white'
                  halign: 'center'
                  valign: 'center'
                  size_hint: 1, None
                  multiline: False
              AnchorLayout:
                  anchor_x: 'center'
                  anchor_y: 'center'
                  MDRoundFlatButton:
                      text: 'Add task'
                      id: addTaskButton
                      on_press: root.addTask()
                      size_hint: 1, 0.5
                      theme_text_color: &quot;Custom&quot;
                      text_color: 1, 1, 1, 1
                      line_color: 1, 1, 1, 1
  </code></pre>