title: Python Tk - Dynamically change button, defined in function, on click
body: <p>I am new to making GUIs with Python and what I am trying to do should be pretty simple. Essentially, I have a dialog class that I use to instantiate a dialog in my program.  One of the things on this dialog is a button that I want to use to change color. I want the user to be able to click the button, be taken to a color chooser, then return to the dialog with the button changing to the color that was chosen.  In my dialog class, here is where I define the button.</p>
  
  <pre><code>def body(self, master):
  
    Label(master, text="Track URL:").grid(row=0)
    Label(master, text="Short label:").grid(row=1)
    Label(master, text="Long label:").grid(row=2)
    b = Button(master, text="Color",bg="white",command=self.chooseColor).grid(row=3)
  
    self.e1 = Entry(master)
    self.e2 = Entry(master)
    self.e3 = Entry(master)
  
    self.e1.grid(row=0, column=1)
    self.e2.grid(row=1, column=1)
    self.e3.grid(row=2, column=1)
  
    return self.e1 # initial focus
  </code></pre>
  
  <p>Then I just want a simple function to choose the color</p>
  
  <pre><code>   def chooseColor(self):
     color = askColor()
     b["bg"] = color
  </code></pre>
  
  <p>I understand that b is now out of scope, so I can't change it, but I don't understand how to get the color chosen in a place where I can change the button color.  Any help would be greatly appreciated.</p>