global name is not defined - but this is actually a function's name

Amit Khemka khemkaamit at gmail.com
Fri Sep 21 02:12:31 EDT 2007


On 9/21/07, Mridula Ramesh <mridula.ccpl at gmail.com> wrote:
> hi.
>
> i'm a beginner and i'm trying to get the hang of classes and functions. my
> code looks like this:
>
>
> <code>
> class showRecord(main):
>     def __init__(self):
>         global gmax
>         #now to create the screen by placing all the widgets
>         rt = Tk()
>         showbuttons()
>         #call the scroller to DoSomething
>         scroll()
>
>     def showbuttons(self):
>         # NAVIGATION BAR------
>         NavBut1 = Button(rt, text="|<", width=6, height=2,
> bg="DarkSeaGreen", fg="Black")
>         NavBut1.grid(row=10, column=20, padx=6, pady=6, columnspan=3)
>         NavBut2 = Button(rt, text="<<", width=6, height=2,
> bg="DarkSeaGreen", fg="Black")
>         NavBut2.grid (row=10, column=25, padx=6, pady=6, columnspan=3)
>         #widget bindings
>         NavBut2.bind('<Button-1>', lambda e:GoPrev(ctr))
> </code>
>
>
> my problem is at the 6th line: showbuttons()
> the error says "global name "showbuttons" is not defined.... but it's not a
> global variable. what am i doing wrong?

use self.showbuttons()

> also, should i say ...
>
> def showbuttons(self):

This should work !


Cheers,

-- 
----
Amit Khemka
website: www.onyomo.com
wap-site: www.owap.in



More information about the Python-list mailing list