title: Modifying a label's text to display a function result after entering a screen in a python's kivy framework application
body: <p>I'm building simple android app using python kivy framework to classify handwritten digits using neural network. The app consists of three screens: main screen, camera screen that opens the camera and allows capturing a photo and saving it in the same directory, and a result screen that displays the result after feeding the image to a neural network. The problem is that I do not know how to edit this code so that upon capturing a photo and entering the results screen, the text of the 'label' in ResultScreen changes to display the result being computed from a function. Thanks in advance for help.
  Here is the code:</p>
  <pre><code>from kivy.lang.builder import Builder
  from kivy.uix.screenmanager import ScreenManager, Screen
  from kivy.uix.boxlayout import BoxLayout
  import numpy as np
  import pickle
  import cv2
  import time
  import ANN
  # load the trained model
  trained_model = pickle.load(open('trained_model.sav', 'rb'))
  
  
  screen_helper = &quot;&quot;&quot;
  ScreenManager:
      MenuScreen:
      CameraScreen:
      ResultScreen:
  &lt;MenuScreen&gt;:
      name: 'menu'
      MDLabel:
          text: 'Digit Classifier'
          bold: True
          halign: 'center'
      MDRectangleFlatButton:
          text: 'Open Camera'
          pos_hint: {'center_x':0.5,'center_y':0.4}
          on_press: root.manager.current = 'camera'
  
  &lt;CameraScreen&gt;:
      name: 'camera'
      orientation: 'vertical'
      padding_bottom: '100px'
      Camera:
          id: camera
          resolution: (400,400)
          play: True
      MDRectangleFlatButton:
          text: 'capture'
          pos_hint: {'center_x':0.5,'center_y':0.1}
          on_press: root.image_to_digit()
          on_press: root.manager.current = 'result'
          
  
          
  &lt;ResultScreen&gt;:
      name: 'result'
      on_enter: root.displayResult()
      MDLabel:
          name:'label'
          text: ''
          halign: 'center'
      MDRectangleFlatButton:
          text: 'menu'
          pos_hint: {'center_x':0.5,'center_y':0.1}
          on_press: root.manager.current = 'menu'
      MDRectangleFlatButton:
          text: 'recapture'
          pos_hint: {'center_x':0.5,'center_y':0.2}
          on_press: root.manager.current = 'camera'
  &quot;&quot;&quot;
  
  
  
  class MenuScreen(Screen):
      pass
  
  
  class CameraScreen(Screen, BoxLayout):
  
      def capture(self):
          camera = self.ids['camera']
          timestr = time.strftime(&quot;%Y%m%d_%H%M%S&quot;)
          pic_name = &quot;IMG_{}.png&quot;.format(timestr)
          camera.export_to_png(pic_name)
          return pic_name
  
  
      def image_to_digit(self):
          '''Takes an image name as a parameter and uses the pre-trained model
          to predict the digit and return it as an integer'''
          # opens the image as an nd-array. The image file should be in the same
          # directory as that of main.py
          image = self.capture()
          img = cv2.imread(image, cv2.IMREAD_GRAYSCALE)
  
          # resize the image
          img = cv2.resize(img, (28, 28), interpolation=cv2.INTER_AREA)
  
          # inverting the color of the picture (to match the trained set)
          img = cv2.bitwise_not(img)
  
          # reshaping image to fit to the network
          img = img.reshape((784, 1))
  
          # feeding the image to the model
          digit = trained_model.forward_propagation(img)
          result = open('result_file.txt','w')
          result.write(str(np.argmax(digit)))
          result.close()
  
  
  class ResultScreen(Screen):
      def displayResult(self):
          result = open('result_file.txt','r')
          digit = result.read()
          result.close()
  
  
  # Create the screen manager
  sm = ScreenManager()
  sm.add_widget(MenuScreen(name='menu'))
  sm.add_widget(CameraScreen(name='camera'))
  sm.add_widget(ResultScreen(name='result'))
  
  
  class DemoApp(MDApp):
  
      def build(self):
          screen = Builder.load_string(screen_helper)
          
          return screen
  
  
  DemoApp().run()```
  </code></pre>