[Tutor] what am I missing?

Ignacio Vazquez-Abrams ignacio@openservices.net
Sat, 1 Sep 2001 02:07:00 -0400 (EDT)


On Sat, 1 Sep 2001, William Perry wrote:

Whoops.

> from Tkinter import *
> from ScrolledText import *

box=None

> def doSearch(event):

    global box

>     sTerm=StringVar()
>     #print 'HERE'
>     box=Toplevel()
>
>     label=Label(box, text='Enter term').pack()
>     entry=Entry(box)
>     Button(box, text='Look For', command=search).pack()
>     entry.pack()
>     entry.focus()
>     display=ScrolledText(box, width=40, height=20, bg='white').pack(expand=YES, fill=BOTH)
>
>
>
>     #sTerm=entry.get
>     #search(sTerm)
>     #print sTerm
>
> def quit():
>     root.quit()
>
> def search():

    global box

>     sTerm=StringVar()
>     sTerm=box.entry.get()  #produces attribute error as below
>     print sTerm
>     #root.insert(END, sTerm)   ##############
>     #lbox.insert(END, sTerm)   # doesn't work
>     #fr.lbox.insert(END, sTerm) ################
>     display.insert(sTerm)
>     #pass
>
>
>
>
>
> root=Tk()
> fr=Frame(root)
> button=Button(fr)
> button['text']= 'Search'
> button.bind('<Button-1>', doSearch)
> button.pack()
>
> lbox=ScrolledText(fr, height=20, width=40, bg='white').pack(expand=YES, fill=BOTH)
> #root.insert(END, 'Word') # doesn't work
> Button(fr, text='QUIT', command=quit).pack()
> fr.pack()
>
> root.mainloop()
>
>
> Error produced when the ' Look For ' button is pressed
>
> Exception in Tkinter callback
> Traceback (most recent call last):
>   File "c:\python21\lib\lib-tk\Tkinter.py", line 1285, in __call__
>     return apply(self.func, args)
>   File "C:\WINDOWS\Desktop\Programing\getdata.py", line 31, in search
>     sTerm=box.entry.get()
> NameError: global name 'box' is not defined
>
>
> Thanks..
> Bill Perry
>
>

-- 
Ignacio Vazquez-Abrams  <ignacio@openservices.net>