Get()

Sam Garson peanut.sam at googlemail.com
Sat Dec 15 13:48:45 EST 2007


Hello all

I am a python "n00b", however I can't find a solution to this problem
anywhere.

I am using a simple setup - entry box, button and list box, the contents of
the entry being inserted into the list box:

from Tkinter import *

def insert():
    name = ent.get()
    box.insert(0, name)
    ent.delete(0, END)

root = Tk()

ent = Entry(root, fg = '#3a3a3a', bg = 'white', relief = 'groove').grid(row
= 0, padx = 3, pady = 3)

button = Button(root, text = "Remember", command = insert, relief =
'groove', fg = '#3a3a3a').grid(row = 0, column = 1, padx = 3, pady = 3)

box = Listbox(root, bg = '#ebe9ed', relief = 'groove').grid(row = 2,
columnspan = 2, sticky = W+E, padx = 3)

root.mainloop()


When I type something and press the button, i get this error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
    return self.func(*args)
  File "C:\My Documents\My Python\Notes.py", line 6, in insert
    name = ent.get()
AttributeError: 'NoneType' object has no attribute 'get'

I am puzzled as to the last line...

Help?

Sam

-- 
I intend to live forever - so far, so good.

SaM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071215/d8a4b624/attachment.html>


More information about the Python-list mailing list