Tkinter._test() does not work. NameError: name ‘Tkinter’ is not defined

Maricela Bruss Asks:


I am trying to get started with Tkinter.  I checked ‘import _tkinter’ and ‘import Tkinter’ – and they seem to be fine with no error whatsoever.

I am getting stuck in the third test,

>>> Tkinter._test()

>>> tkinter._test()

The error  message:

Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
NameError: name ‘Tkinter’ is not defined

I have identifed by version as Tkinter (caps T). however i also tried tkinter, just in case.

Any help would be appreciated !

NEIL Fackler writes:

This means python doesn’t know what a ‘TKinter’ is. This probably implies that you have not imported the Tkinter module before the Tkinter._test().

Try out his:

>>> import Tkinter
>>> Tkinter._test()

Notice that:

>>> from Tkinter import * will not work because you need the entire Tkinter directory for this to work –

from Tkinter import * also wastes namespace.

Maricela Bruss Writes:

Thanks — hit the bulls eye !
Very stupid of me :)

Broadbent Writes:

I am getting a similar error
NameError: name ‘tk’ is not defined.

The documentation at Tkinter does not specify anything of this.

Thanks lot.