I have been writing a program for a GUI based plotter using matplotlib and tkinter. I have added a toplevel window for some options. I want to execute a function and quit the toplevel window after clicking a button. Is that possible?
The problem that I face is that I have used a toplevel window which has to be called from the main window. SO I defined a function that contains this toplevel window. If I define another function that can do multiple operations, it cannot recognize the toplevel window. I could define it all under a class but am unsure if it works. Here's a part of my code that contains the toplevel window.
def plt_options(arg):
global lg_var,col_var,line_type_var,marker_var
plt_opt = Toplevel(app)
lg_var = StringVar(None)
lg_text = Label(plt_opt,text='Legend').grid(row=0,column=0,sticky=E)
lg_box = Entry(plt_opt,textvar=lg_var)
lg_box.grid(row=0,column=1,sticky=W)
col_var = StringVar(None)
col_var.set('blue')
col_text = Label(plt_opt,text='Color').grid(row=1,column=0)
col_chooser = OptionMenu(plt_opt,col_var,'blue','green','red','cyan',\
'magneta','yellow','black','white')
col_chooser.grid(row=1,column=1)
line_type_var = StringVar(None)
line_type_var.set('Solid')
line_type_text = Label(plt_opt,text='Line type').grid(row=2,column=0)
line_chooser = OptionMenu(plt_opt,line_type_var,'Solid','Dashed',\
'Dotted','Dash-Dotted','None')
line_chooser.grid(row=2,column=1)
marker_var = StringVar(None)
marker_var.set('None')
marker_text = Label(plt_opt,text='Marker').grid(row=3,column=0)
marker_chooser = OptionMenu(plt_opt,marker_var,'Plus','Dot','Circle',\
'Star','Pentagon','Square','Cross','Diamond','Hexagon','Triangle')
marker_chooser.grid(row=3,column=1)
ok_btn = Button(plt_opt,text='OK',command=testing).grid()