String variable just refuses to be turned into an integer
<p>I am writing a python GUI application which takes an entry from the user, converts it into an integer, and then uses that integer with the datetime module. However I have run into a problem which hopefully you can help with.</p>

<p>I am using Tkinter to construct a GUI with 3 elements, an entry box, a "GO!" button, and a "quit" button. Here is my simplified code:</p>

<pre><code>class MyFirstGUI:
    def __init__(self, master):

        numberdate = StringVar()

        Label(root,text="Enter the Number of days you would like to search in").grid(row=0)
        self.a = Entry(root,textvariable=numberdate )
        self.a.grid(row=0, column=1)

        self.close_button = Button(master, text="Close", command=master.quit)
            self.close_button.grid(row=3, column=1)

        self.macro_button = Button(master, text="GO!", command=self.macro)
            self.macro_button.grid(row=4, column=1)
</code></pre>

<p>Now this seems simple enough, I know I have saved the variable as a StringVar but I will address that later. Now when the "GO!" button is pressed, it executes another portion of code, this is as follows:</p>

<pre><code>numberdate = self.a.get() 

int(numberdate)

date_threshold = datetime.datetime.today() - datetime.timedelta(days=numberdate)
</code></pre>

<p>However whenever I run this code, python throws the following error at me:</p>

<pre><code>TypeError: unsupported type for timedelta days component: str
</code></pre>

<p>Now obviously this means the variable numberdate hasn't been converted into an integer, it is still a number, but for the life of me I can't work out why.</p>

<p>I've tried saving the variable as an IntVar in the first half of the code, but still no luck.</p>

<p>Is there an obvious mistake in my code that I am missing, or am I just going mad?</p>

<p>The conversion happens, but nobody was listening.  You have to rebind the name to the return value:</p>

<pre><code>numberdate = int(numberdate)
</code></pre>

python python-3.x tkinter