tkInter scoping problem ?
bernard
bh at cellware.de
Fri Oct 8 07:17:58 EDT 1999
To display an image on a canvas I tried
PhotoImage(name=name, file="./" + name + ".gif")
c.create_image(x, y, anchor=NW, image=name)
which works fine.
However when I use this code in the __init__ method of a class
class TeleTubby:
def __init__(self, c, name, x, y):
PhotoImage(name=name, file="./" + name + ".gif")
c.create_image(x, y, anchor=NW, image=name)
...
I get the error
tcl Error: image "tinky" doesn't exist
Then trying
self.pic = PhotoImage(file="./" + name + ".gif")
c.create_image(x, y, anchor=NW, self.pic)
this time I get no error but no image.
But then this worked fine
global pic
pic = PhotoImage(file="./" + name + ".gif")
c.create_image(x, y, anchor=NW, pic)
and so did using a class variable
TeleTubby.pic = PhotoImage(file="./" + name + ".gif")
c.create_image(x, y, anchor=NW, image=TeleTubby.pic)
Why is this ? And is there any way I can get the first two formulations
(image name or instance variable) to work in the context of a class
method ?
Confused-ly - bernard
More information about the Python-list
mailing list