tkinter in tkinter makes value disappear (python 3.4.3)
<p>I wrote this piece of code, which is supposed to ask a user if all of his files have the same date and if yes, that he should write his date into a grid.
After entering the dates both windows should disappear and i want to keep the date.
Unfortunately I don't manage to let the first Input-Box disappear and after this whole procedure the entry date is [ ] again.</p>

<pre><code> from tkinter import *

    entry_date = []
            if amountfiles == 1:
                def moredates():
                    master.destroy()

                def setdate():
                    def entry_date():
                        entry_date = e1.get()
                        entry_date = str(entry_date)
                        print("Date for all files is: ",entry_date)
                        master.destroy()

                    def quit():
                        sys.exit()

                    master = Tk()
                    Label(master, text="Please enter date (format YYYYMMDD, i.e. 20160824): ").grid(row=0)
                    e1 = Entry(master)
                    e1.grid(row=0, column=1)
                    Button(master, text='Quit', command=master.destroy).grid(row=3, column=1, sticky=W, pady=4)
                    Button(master, text='Insert', command=entry_date).grid(row=2, column=1, sticky=W, pady=4)
                    mainloop( )

                master = Tk()
                Label(master, text="Do all files have the same date?").grid(row=0)
                Button(master, text='No...', command=moredates).grid(row=2, column=0, sticky=W, pady=4)
                Button(master, text='Yes!', command=setdate).grid(row=1, column=0, sticky=W, pady=4)
                Button(master, text='Close &amp; Contiune', command=master.destroy).grid(row=3, column=0, sticky=W, pady=4)
                mainloop( )
</code></pre>

<p>As the outer <code>master</code> variable is re-assigned in the function <code>setdate()</code>, the call <code>master.destroy()</code> will only close the new <code>master</code>, not the outer <code>master</code>.  Try modifying the function <code>setdate()</code> as below:</p>

<pre><code>def setdate():
    def append_date():
        date = e1.get() # get the input entry date
        entry_date.append(date) # save the input date
        print("Date for all files is: ", date)
        master.destroy()

    top = Toplevel() # use Toplevel() instead of Tk()
    Label(top, text="Please enter date (format YYYYMMDD, i.e. 20160824): ").grid(row=0)
    e1 = Entry(top)
    e1.grid(row=0, column=1)
    Button(top, text='Quit', command=master.destroy).grid(row=3, column=1, sticky=W, pady=4)
    Button(top, text='Insert', command=append_date).grid(row=2, column=1, sticky=W, pady=4)
    master.wait_window(top) # use Tk.wait_window()
</code></pre>

python tkinter python-3.4