[Tutor] calling functions with buttons - why doesn't this wor k??

alan.gauld@bt.com alan.gauld@bt.com
Tue, 31 Oct 2000 11:27:25 -0000

> There are alot of things I don't understand about Tkinter.

Join the club. :-)

> doesn't work.  When it is run it executes hi() but not when 

Thats because of the ()...

> def hi():
>     print 'hi'
> f = Frame(root)
> b = Button(text='hi', command=hi())

  b = Button(text='hi', command=hi)

hi is the function object. hi() executes the function and stores 
the return value in the command option. In your case hi() returns 
'None' so clicking the button executes the empty (none) command.

As to why the title doesn't work, I'm not sure but from memory,
isn't the title set as a function:


rather than by assignment as you have done?

Alan G.