Help please with menubars

Chad Netzer cnetzer at
Sat Sep 28 00:23:47 EDT 2002

On Friday 27 September 2002 20:54, mongo57a at wrote:
> Specifically: I have
> an "exit" item on the menubar and if the user clicks on "exit", the
> window should be closed. What I don't want is a pulldown with "exit"
> as a button option.

I'm assuming you are talking about Tkinter here:

If so, your 'menubar' is a Tk menu, with cascade buttons in it.  It is 
also possible to attach a "command" button to it:

import Tkinter
Tk = Tkinter

def output_func():
    print "T.I.S.M. is a fine Aussie band."

root = Tk.Tk()  #This opens a Toplevel()

menubar = Tk.Menu( root )
menubar.add_command( label='T.I.S.M.', command=output_func )

root.configure( menu=menubar )   #Attach menubar to the Toplevel


And if that doesn't work for you, then use the 'bind' command on the 
button or widget that you want to trigger the exit, and look for 
"<ButtonPress-1>" events.  Attach that to an exit function.

Other window toolkits should have analogous methods of doing this.

P.S. In my version, I just reuse the root Toplevel; you can also attach 
a menubar at creation time.


Chad Netzer
cnetzer at

More information about the Python-list mailing list