title: How to add a progress bar while executing process in tkinter?
body: <p>I'm building a little app to generate a word document with several tables, since this process takes a little long to finish I'd like to add a progress bar to, make it a little less boring the wait for the user, so far I manage to make the following method:</p>
  <pre><code>def loading_screen(self,e,data_hold=None):
  
      &quot;&quot;&quot;
      Generates a progress bart to display elapset time
      &quot;&quot;&quot;
  
      loading = Toplevel()
      loading.geometry(&quot;300x50&quot;)
      #loading.overrideredirect(True)
      progreso = Progressbar(loading,orient=HORIZONTAL,length=280,mode=&quot;determinate&quot;)
      progreso.pack()
      progreso.start(10)
  
      #progreso.destroy()
  
  </code></pre>
  <p>This method is supposed to run right after the user clicks a button of the next <code>Toplevel</code>.</p>
  <pre><code>
  def validate_data(self):
  
      &quot;&quot;&quot;
      genera una venta para validar los datos ingresadados y hacer cualquier correccion
      previa a la generacion de los depositos finales
      &quot;&quot;&quot;
      if self.datos:
  
          venta = Toplevel()
          venta.title(&quot;Listado de depositos por envasadora&quot;)
          venta.geometry(&quot;600x300&quot;)
          columnas = [&quot;ID&quot;,&quot;Banco&quot;,&quot;Monto&quot;,&quot;Envasadora&quot;]
          self.Tree_datos = ttk.Treeview(venta,columns=columnas,show=&quot;headings&quot;)
          self.Tree_datos.pack()
  
          for i in columnas:
              self.Tree_datos.heading(i,text=i)
  
          for contact in self.datos:
              self.Tree_datos.insert('', END, values=contact)
  
          self.Tree_datos.column(&quot;ID&quot;,width=20)
          #Tree_datos.column(&quot;Banco&quot;,width=100)
          imprimir_depositos = Button(venta,text=&quot;Generar Depositos&quot;,command=self.generar_depositos)
          imprimir_depositos.pack(fill=BOTH,side=LEFT)
  
          editar_deposito = Button(venta,text=&quot;Editar seleccion&quot;,command=self.edit_view)
          editar_deposito.pack(fill=BOTH,side=RIGHT)
          imprimir_depositos.bind(&quot;&lt;Button-1&gt;&quot;,self.loading_screen)
          #return get_focus ()
          def get_focus(e):
              self.valor_actualizado = self.Tree_datos.item(self.Tree_datos.focus()) [&quot;values&quot;]
              self.Tree_datos.bind(&quot;&lt;ButtonRelease-1&gt;&quot;,get_focus)
          else:
              messagebox.showinfo(message=&quot;No hay datos que mostra por el momento&quot;,title=&quot;No hay datos!&quot;)
  
  </code></pre>
  <p>The command that generates the doc file is this (along with other methods that are not relevant for now I guess):</p>
  <pre><code>def generar_depositos(self):
  
      documento = Document()
      add_style = documento.styles [&quot;Normal&quot;]
      font_size = add_style.font
      font_size.name = &quot;Calibri&quot;
      font_size.size = Pt(9)
      table_dict = {&quot;BPD&quot;:self.tabla_bpd,&quot;BHD&quot;:self.tabla_bhd,&quot;Reservas&quot;:self.tabla_reservas}
      self.tabla_bhd(documento,&quot;La Jagua&quot;,&quot;2535&quot;)
          #for banco,env,deposito in datos_guardados:
              #table_dict [banco] (documento,env,deposito)
          #   documento.add_paragraph()
  
      self.set_doc_dimx(documento,margen_der=0.38,margen_izq=0.9,margen_sup=0.3,margen_infe=1)
      sc = documento.sections
      for sec in sc:
          print(sc)
      documento.save(&quot;depositos.docx&quot;)
  </code></pre>
  <p>So basically what I want is to display the animated progress bar while this method is running, I read about threading but I don't how to implement it on my code.</p>