How can I decrease the number on a button?
<p>I'm trying to create a GUI that has only one button. Each time the button is pressed the number on the button should decrease. So I wrote this:</p>

<pre><code>import Tkinter

def countdown(x):        
   x -= 1

top = Tkinter.Tk()

def helloCallBack():    
    countdown(x)    

B = Tkinter.Button(top, text=x, command=helloCallBack )   
B.pack()       
top.mainloop()
</code></pre>

<p>I want that button's text to be like 5 4 3 2 1, so where should I put the <code>x=5</code>?</p>

<p>As described in the "Button" section of <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/control-variables.html" rel="nofollow">http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/control-variables.html</a>, you need to create a special <code>StringVar</code> to make the button dynamically update. You can pass the <code>StringVar</code> into the <code>textvariable</code> variable of the <code>Button</code> constructor and update the <code>StringVar</code> value inside the <code>countdown()</code> function. <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/button.html" rel="nofollow">http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/button.html</a> states that <code>textvariable</code> is </p>

<blockquote>
  <p>An instance of StringVar() that is associated with the text on this button. If the variable is changed, the new value will be displayed on the button.</p>
</blockquote>

python python-2.7 tkinter