title: Kivy - Refreshing Progress Bar with timer
body: <p>Is there a more efficient / shorter way to write this code ? I feel like I am overcoding progress bar animation by defining a function, using self level variables ect. The point I had difficulity was updating progress bar image each time its value increases. At first I tried sleep but it didn't work as it did not update the progress bar. It only showed update when it is full. Then I switched to Clock.schedule and now it is working but I feel like it is longer than it should be.</p>
  <pre><code>from kivy.app import App
  from kivy.lang import Builder
  from kivy.uix.widget import Widget
  from kivy.clock import Clock
   
  Builder.load_string(&quot;&quot;&quot;
  
  &lt;MyLayout&gt;
  
          BoxLayout:
                  orientation: &quot;vertical&quot;
                  size: root.width, root.height
                  spacing: 20
                  padding: 50
  
                  Button:
                          text:       'OK'
                          on_release: root.start_filling()
  
                  ProgressBar:
                          id:         progress_bar
                          min:        0
                          max:        100
                          value:      35
  
  &quot;&quot;&quot;)
  
  class MyLayout(Widget):
  
          prg_bar_counter = 0
          prg_bar_event = &quot;&quot;
  
          def fill_more(self, dt=0):
                  
  
                  self.ids.progress_bar.value += 10
                  self.prg_bar_counter += 1
                  if self.prg_bar_counter &gt; 3: Clock.unschedule(self.prg_bar_event)
          
          def start_filling(self):
  
                  self.prg_bar_event = Clock.schedule_interval(self.fill_more, 1)
                  
  
  
  class MyApp(App):
  
      def build(self):
          return MyLayout()
  
  
  if __name__.endswith('__main__'):
      MyApp().run()
  </code></pre>