[Tutor] Do I have to initialize TKInter before I can use it?

Nathan Pinno falcon3166 at hotmail.com
Tue Nov 15 05:42:32 CET 2005

Alan and all,

I imported it, but its not there. I tried using the Message one found in it,
but I got an error message:
>>> import Tkinter
>>> tk = Tkinter.Tk()
>>> Tkinter.Message("Help","Help!")

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in -toplevel-
  File "D:\Python24\lib\lib-tk\Tkinter.py", line 2640, in __init__
    Widget.__init__(self, master, 'message', cnf, kw)
  File "D:\Python24\lib\lib-tk\Tkinter.py", line 1862, in __init__
    BaseWidget._setup(self, master, cnf)
  File "D:\Python24\lib\lib-tk\Tkinter.py", line 1840, in _setup
    self.tk = master.tk
AttributeError: 'str' object has no attribute 'tk' 

What does this mean, and how can I get it working?

-----Original Message-----
From: Alan Gauld [mailto:alan.gauld at freenet.co.uk] 
Sent: November 14, 2005 9:35 PM
To: Nathan Pinno; Tutor Mailing List
Subject: Re: [Tutor] Do I have to initialize TKInter before I can use it?


> I am having problems. The latest error message I got was:
>    tkMessageBox.showinfo("Hockey",
> NameError: name 'tkMessageBox' is not defined

A NameError means Python doesn't recognise the name.
Usually that's because either you didn't declare the variable or you forgot
to import the module or you spelled it wrong.

In this case I'd guess you forgot the import?

Python error messages are really quite helpful if you just stop and think
about what they are saying for a few minutes.

Alan G
Author of the learn to program web tutor

More information about the Tutor mailing list