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

Alberto Troiano alberto.troiano at gmail.com
Tue Nov 15 16:51:15 CET 2005


Hey Nathan
I think this is what you are looking for

####Code Below####
from Tkinter import *
import tkMessageBox

tkMessageBox._show("Windows Title","This is the
description",icon=tkMessageBox.INFO,type=tkMessageBox.OK)
###End of Code####

Regards

Alberto

-----Mensaje original-----
De: tutor-bounces at python.org [mailto:tutor-bounces at python.org] En nombre de
Nathan Pinno
Enviado el: Martes, 15 de Noviembre de 2005 00:43
Para: 'Alan Gauld'; 'Tutor Mailing List'
Asunto: Re: [Tutor] Do I have to initialize TKInter before I can use it?

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-
    Tkinter.Message("Help","Help!")
  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?
Nathan

-----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?

Nathan,

> 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
http://www.freenetpages.co.uk/hp/alan.gauld


_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list