[Tutor] help with .get in Tkinter

Alan Gauld alan.gauld at freenet.co.uk
Sun Feb 20 19:09:06 CET 2005


Mark,

There are two problems here:

> from Tkinter import *
> def go():...

> e=Entry(main)
> e.pack()

This is OK but...

> b=Button(main,text='OK',command=go()).pack()

Problem 1:
This will store None in b because pack() always returns None.

Problem 2:
> For some reason the function is called before I click the button,
and
> I get .10037088 before I have done a thing.

Thats because you are calling go() inside the widget specification,
you need to pass a reference to the function instead - ie miss out
the parens:

b=Button(main,text='OK',command=go)
b.pack()

That should fix it.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list