Apologies for the basic nature of the question. Tkinter has me totally stumped.
I'm trying to construct an application with a menu bar, one of the choices would pull up a dialog where the user enters two values and then either presses an "Enter" or "Cancel" button. Either button press should then close the window.
I can construct the main window and the 'pop-up' to enter the values, I've gone through all examples of extracting text and closing the window after the button press but I'm still coming up empty. Here is the framework I'd like to use:
from Tkinter import *
#
# Functions to perform functions selected from main window
#
def enter_values():
new_window = Toplevel(root)
Label(new_window, text="Value 1").grid(sticky=W,row=0)
e1=Entry(new_window,width=40).grid(row=0,column=1,sticky=W)
Label(new_window, text="Value 2").grid(pady=20,sticky=W,row=1)
e2=Entry(new_window,width=20).grid(row=1,column=1,pady=20,sticky=W)
ok= Button(new_window, text="Enter",command=lambda: callback("OK")).grid(column=0,row=4,pady=30)
cancel = Button(new_window,text="Cancel",command=lambda: callback("CANCEL")).grid(column=1,row=4,pady=30)
def callback(button):
if button == "OK":
print "OK"
elif button == "CANCEL":
print "Cancel"
else:
print "no idea"
#
# Following section defines the display window
#
root = Tk()
root.minsize(500,200)
root.geometry("800x300")
root.wm_title("Some clever title here")
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="New", command=enter_values)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)
root.config(menu=menubar)
root.mainloop()