Menus with Tkinter ??

Carles Sadurní Anguita isard at localhost.localdomain
Mon Sep 11 23:52:16 CEST 2000


Hello,

I'm learning python and tkinter and I've found an amazing "problem". Why
does this code work

--------------------- This code works --------------
#!/usr/bin/python
from Tkinter import *

def ah():
	print "Ah!"
def oh():
	print "Oh!"

root = Tk()
menubar = Menu(root)
menuarxiu = Menu(menubar, tearoff=0)
menuarxiu.add_command(label="Ah!", command=ah)
menuarxiu.add_command(label="Oh!", command=oh)
menubar.add_cascade(label="arxiu", menu=menuarxiu)
root.config(menu = menubar)
mainloop() 
----------------------------------------------------

and this one doesn't


--------------------- This code doesn't work -------

#!/usr/bin/python
from Tkinter import *

def ah(n):
	print n

root = Tk()
menubar = Menu(root)
menuarxiu = Menu(menubar, tearoff=0)
menuarxiu.add_command(label="Ah!", command=ah(0))
menuarxiu.add_command(label="Oh!", command=ah(1))
menubar.add_cascade(label="arxiu", menu=menuarxiu)
root.config(menu = menubar)
mainloop() 
____________________________________________________


It prints 0 and 1 before the user pops the menu!


Thanks in advance
-- 
------------------------------------------------------------------------
Carles Sadurní Anguita    |   no había que cumplir promesas,
                          |   el cansancio era de placer,
Quita _mira_la_firma para |   las lágrimas eran de risas...
responder.                |   y parece que aún fue ayer.
                          |           Los Suaves
------------------------------------------------------------------------



More information about the Python-list mailing list