Canvas Object Tags: Help for Rookie
John Smith
someone at microsoft.com
Wed Dec 18 16:38:34 EST 2002
Pythoners:
I am goofing around with the canvas class and trying to reference line
objects drawn on a canvas by their tags. I thought the easiest appraoch
would be to give each new line an tag set by an integer counter. A short
version of my code looks like:
class myCanvas:
def __init__(self, root):
tagid = 0
>>>Some code
self.btn = Button(self.frame, text='OK')
self.btn.pack(side=LEFT)
self.btn.bind('<Button-1>', self.lineupdate(tagid))
>>>Some code
def lineupdate(self, tag, event=None):
coordlist = self.canvas.coords(tag)
lastx = coordlist[2]
lasty = coordlist[3]
tagid = tagid + 1
newx = lastx + 50
newy = lasty - 50
self.canvas.create_line(lastx, lasty, newx, newy, arrow='last', width=2,
fill='red', tags=self.tagid)
def firstline(self):
self.canvas.create_line(10, 10, 200, 200, arrow='last', width=2,
fill='red', tags=self.tagid)
mc = myCanvas(root)
mc.firstline()
root.mainloop()
A get an attribute error in the lineupdate function for the
self.canvas.coords(tag) function. My understanding is that the function
should return the coordinates of the line object.
Any help?
More information about the Python-list
mailing list