how to open a new window only when i click menuitem. for example, check out this following code, in which Toplevel window comes up as soon as u run the code. i dont want that. i want the new window to open only when click 'one' in the menu bar. similarly 'second' like that.
also i want close the window when the user closes the window and again when he clicks on the 'one' all Entry fields should be empty.
can we create a form so that all Entry fields and Labels arranged in a proper manner?
please check out this code and please tell where im wrong. :?: :-|
from Tkinter import *
import tkMessageBox
import tkSimpleDialog
class form(tkSimpleDialog.Dialog):
def __init__(self,root):
self.menubar=Menu(root)
root.config(menu=self.menubar)
self.parent=root
#self.top=top
self.formmenu=Menu(self.menubar)
self.formmenu.add_command(label="one",command=self.one())
self.menubar.insert_cascade(1,label="Form",menu=self.formmenu)
self.parent.focus_force()
def one(self):
tkMessageBox.showinfo("one","this first.......")
self.top=Toplevel(master=self.parent)
Label(self.top,text="Name: ").pack()
e1=Entry(self.top)
e1.pack()
b1=Button(self.top,text=" Ok ",command=self.ok)
b1.pack()
e1.focus_set()
def ok(self):
tkMessageBox.showinfo("one","the first form is responding to click.......")
self.top.destroy()
root=Tk()
#top=Toplevel()
form(root)
#root.mainloop()
Edit: added code tags vegaseat