title: how to make only the function sleep instead of the entire program in kivy
body: <p>so like basically, sleep stops the entire script and this isnt good and I most likely dont want that, so any solutions to this? (it is for this boy right here):</p>
  <pre><code>    def on_button_click(self):
          global started
          if started==False:
              started=True
              enemyname = self.ids.starta.text
              self.type_text(&quot;&quot;)
              self.hide_widget(self.ids.starta)
              self.hide_widget(self.ids.startb)
  
              self.ids.thingy.opacity = 1
              self.ids.thingys.opacity = 1
              self.ids.thingyss.opacity = 1
              self.type_text(&quot;type this text&quot;)
              sleep(3)
              print(&quot;yes&quot;)
  </code></pre>
  <p>as you can see right here, I've tested stuff and the function right above the sleep gets delayed for 3 seconds but the print is printed instantly no idea how to explain it completely but this causes problems for sure as you can see, anyway I can fix this? (self.type_text uses Clock.schedule_interval and the function is from another question I've asked recently)</p>
  <p>so yeah the main question is: how do I make it so that only this button function pauses instead of the whole thing</p>
  <p>all related parts:</p>
  <pre><code>Builder.load_string(&quot;&quot;&quot;
  
  &lt;BoxLayout&gt;:
      orientation:&quot;vertical&quot;
      spacing:&quot;10dp&quot;
      TextInput:
          text: &quot;type enemy name&quot;
          size_hint:1,3
          id: starta
      Button:
          text:&quot;Start&quot;
          on_press: root.on_button_click()
          size_hint:1,3
          id: startb
      Label:
          id: label
          text: &quot;Enter enemy name and press 'start'&quot;
      Button:
          text:&quot;Fight&quot;
          size_hint: 1,.3
          color:1,0,0,1
          background_color:.5,0,0
          opacity:0
          id: thingy
      Button:
          text:&quot;Guard&quot;
          size_hint: 1,.3
          color:0,0,1,1
          background_color:0,0,.5
          opacity:0
          id: thingys
      Button:
          text:&quot;Heal&quot;
          size_hint: 1,.3
          color:0,1,0,1
          background_color:0,.5,0
          opacity:0
          id: thingyss
          
  &quot;&quot;&quot;)
  
  
  
  class TextBox(BoxLayout):
      cache_text = StringProperty(&quot;&quot;) # For storing the entered text.
      index = NumericProperty(0) # For iteration over cache_text.
      global started
      def hide_widget(self, wid, dohide=True):
          if hasattr(wid, 'saved_attrs'):
              if not dohide:
                  wid.height, wid.size_hint_y, wid.opacity, wid.disabled = wid.saved_attrs
                  del wid.saved_attrs
          elif dohide:
              wid.saved_attrs = wid.height, wid.size_hint_y, wid.opacity, wid.disabled
              wid.height, wid.size_hint_y, wid.opacity, wid.disabled = 0, None, 0, True
  
      def type_text(self, txt, time=0.07):
          self.ids.label.text = &quot;&quot;  # Comment it out to retain the text.
          self.cache_text = txt # Store the entered text here.
          # For more control you may use method Clock.create_trigger.
          self.ev = Clock.schedule_interval(self.update_text, time) # Update text after every 0.25 sec.
  
      def update_text(self, *args):
              if self.index &lt; len(self.cache_text):
                  val = self.cache_text[self.index]
                  self.ids.label.text += val # Appending to existing text.
                  self.index += 1
              else:
                  self.index = 0 # Reset index.
                  self.cache_text = &quot;&quot; # Clear cache.
                  self.ev.cancel() # Cancel text updation.
      def on_button_click(self):
          global started
          if started==False:
              started=True
              enemyname = self.ids.starta.text
              self.type_text(&quot;&quot;)
              self.hide_widget(self.ids.starta)
              self.hide_widget(self.ids.startb)
  
              self.ids.thingy.opacity = 1
              self.ids.thingys.opacity = 1
              self.ids.thingyss.opacity = 1
              self.type_text(&quot;who you are fighting againist is %s, be careful. they are strong.&quot;% enemyname)
  
  
  class Test(App):
      def build(self):
          return TextBox()
  
  Test().run()
  </code></pre>