title: How to trigger changes in button in a comand in Tkinter?
body: <p>I'm new to <code>TKinter</code>. I need to change the text of a <code>button</code> and its <code>state</code> when its clicked, then do some actions, and finally change again its text and state.</p>
  
  <p>The problem is the changes only apply once the function has ended, skipping the first change of state and text. It never changes the <code>Buttons</code> text to "loading" and the button is never disabled.</p>
  
  <p>Here is the code for the problem i'm experiencing:</p>
  
  <pre class="lang-py prettyprint-override"><code>#!/usr/bin/env python
  import tkinter as tk
  import time
  
  
  class Application(tk.Frame):
  
      def __init__(self, master=None):
          super().__init__(master)
          self.master = master
          self.pack(fill=tk.BOTH, expand=1)
          self.create_widgets()
  
      def create_widgets(self):
          self.master.title("CW POS")
  
          cierre = tk.Button(
              self.master,
              command=self.re_imprimir_ultimo_cierre)
  
          cierre["text"] = "foo"
          cierre.pack(fill=tk.BOTH, expand=1)
          self._cierre = cierre
  
          salir = tk.Button(self.master, text="quit", command=self.salir)
          salir.pack(fill=tk.BOTH, expand=1)
  
  
      def salir(self):
          exit()
  
      def re_imprimir_ultimo_cierre(self):
          self._cierre["text"] = "Loading..."
          self._cierre["state"] = tk.DISABLED
  
          # TODO: magic
          time.sleep(2)
  
          self._cierre["text"] = "foo"
          self._cierre["state"] = tk.NORMAL
  
  
  
  root = tk.Tk()
  root.geometry("240x180")
  root.resizable(False, False)
  app = Application(root)
  root.mainloop()
  </code></pre>
  
  <p>How do I make the button show <code>text="loading"</code> and <code>state=DISABLED</code>, while the button is doing my calculations?</p>