Quit button assistance needed
<p>I'm trying to make a code for this topic i'm doing and I've manage to get some of it done but when it comes to quiting my tkinter menu it doesn't close unless I manually close it, I've got the the button for the option to close it but it doesn't work. Can anyone help with my problem. Here's my code below.</p>

<pre><code>import sys
import tkinter
from tkinter import*
import time

global v


global popJ
popJ = 0

def genInput(): #Allows the user to input the data

    gen = Toplevel()
    gen.wm_title("Data Input")
    v = IntVar()
    ent1 = Entry(gen, textvariable = v).pack()
    ent1Txt = Label(gen, text = 'Please input Juvenile Populations')

    ent1Txt.pack()


    v2 = StringVar()
    ent2 = Entry(gen, textvariable = v2)
    ent2Txt = Label(gen, text = 'Please input Adult Populations')
    ent2.pack()
    ent2Txt.pack()

    v3 = StringVar()
    ent3 = Entry(gen, textvariable = v3)
    ent3Txt = Label(gen, text = 'Please input Senile Populations')
    ent3.pack()
    ent3Txt.pack()

    v4 = StringVar()
    ent4 = Entry(gen, textvariable = v4)
    ent4Txt = Label(gen, text = 'Please input Survival rates for Juveniles')
    ent4.pack()
    ent4Txt.pack()

   v5 = StringVar()
   ent5 = Entry(gen, textvariable = v5)
   ent5Txt = Label(gen, text = 'Please input Survival rates for Adults')
   ent5.pack()
   ent5Txt.pack()

   v6 = StringVar()
   ent6 = Entry(gen, textvariable = v6)
   ent6Txt = Label(gen, text = 'Please input Survival rates for Seniles')
   ent6.pack()
   ent6Txt.pack()

   v7 = StringVar()
   ent7 = Entry(gen, textvariable = v7)
   ent7Txt = Label(gen, text = 'Please input the birth rate')
   ent7.pack()
   ent7Txt.pack()

   v8 = StringVar()
   ent8 = Entry(gen, textvariable = v8)
   ent8Txt = Label(gen, text = 'Number of Generations')
   ent8.pack()
   ent8Txt.pack()

   def quit1():   # Needs to be here or it breaks the program
        gen.destroy()            
        return
   def submit():
        global popJ

        popJ = v.get()
        popJtxt = Label(gen, text= v.get()).pack()
        return



    submit1= Button(gen, text="Submit")
    submit1.pack()
    submit1.configure(command = submit)
    return1 = Button(gen, text = 'Return to Menu')
    return1.pack(pady=30)
    return1.configure(command = quit1)    
    return

def genView(): # should display the data
    disp = Toplevel()
    disp.wm_title('Displaying data Values')
    popJuvenilesTxt = Label (disp, text = popJ)
    popJuvenilesTxt.grid(row =1, column = 1)




def menu():  # creates the gui menu 

    menu = Tk()
    menu.wm_title("Greenfly model")

    genInp = Button(menu,text = "Set Generation Values")

    genVew = Button(menu,text = 'Dysplay Generation Values')

    modelCal = Button(menu,text = 'Run model')

    exportData = Button(menu,text = 'Export Data')

    quitProgram = Button(menu,text = 'Quit')

    genTxt = Label(menu, text= 'Input the Generation values')
    genvTxt = Label (menu, text = 'View the current generation values')
    modelTxt = Label (menu, text = 'Run the model')
    exportTxt = Label (menu, text = 'Export data')
    quitTxt = Label (menu, text= 'Exit the program')

    genInp.grid(row=1, column=1)
    genVew.grid(row=2, column=1)
    modelCal.grid(row=3, column=1)
    exportData.grid(row=4 , column=1)
   quitProgram.grid(row=5, column=1)
   genTxt.grid(row=1, column = 2)
   genvTxt.grid(row=2, column = 2)
   modelTxt.grid(row=3, column = 2)
   exportTxt.grid(row=4, column = 2)
   quitTxt.grid(row=5, column = 2)
   genInp.configure(command = genInput)
   genVew.configure(command = genView)
   menu.mainloop()

menu()
</code></pre>

<p>For Tkinter you can just pass <code>gen.quit</code> to the command of a button widget, like so:</p>

<pre><code>close = Button(gen, text = 'Close', command = gen.quit).pack()
</code></pre>

python button tkinter