[Tutor] A problem with a Tkinter program (using the text widget)

Alan Gauld alan.gauld at freenet.co.uk
Sat Feb 5 20:29:32 CET 2005


> Whats wrong here ?? :
> from Tkinter import *
> def p_text():
>     print text.get()
> root=Tk()
> text=Text(root).pack()

pack() retirns None, YOu *must* use two steps:

text = Text(....)
text.pack()

> button=Button(root,text="Click here!!",command=p_text).pack()
> root.mainloop()
>
> I get an error that says that nontype object has no attribute
'get'...
> whats wrong ??

Because your text variable contains None, which doesn't support get...

Don't worry, its one of the most common Tkinter mistakes and
bites most folks at some stage...

Alan G.



More information about the Tutor mailing list