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

For starters, here is a simple code sample for bringing up a child window. You can use a button, or in your case a menu click.

# display message in a child window

from Tkinter import *

def messageWindow():
    # create child window
    win = Toplevel()
    # display message
    message = "This is the child window"
    Label(win, text=message).pack()
    # quit child window and return to root window
    # the button is optional here, simply use the corner x of the child window
    Button(win, text='OK', command=win.destroy).pack()

    
# create root window
root = Tk()
# put a button on it, or a menu
Button(root, text='Bring up Message', command=messageWindow).pack()
# start event-loop
root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.