[Tutor] Tk canvas question

=?gb2312?B?zPrKrw==?= winglion1 at 163.com
Wed Aug 24 05:45:45 CEST 2005

>You can use the itemcget() method of the canvas to retrieve the text:
> >>> root = Tk()
> >>> canvas=Canvas(root)
> >>> t=canvas.create_text(10, 10, text='Hello', tag='1')
> >>> canvas.pack()
> >>> canvas.itemcget('1', 'text')
>There does seem to be something strange with reusing the tags - if I create a new element with tag '1' I can't retrieve it by tag:
> >>> canvas.delete('1')
> >>> t=canvas.create_text(10, 10, text='Goodbye', tag='1')
> >>> canvas.itemcget('1', 'text')
> >>> canvas.find_withtag('1')
>even though if I ask what tags are on the item it says '1':
> >>> t
> >>> canvas.itemcget(2, 'text')
> >>> canvas.itemcget(2, 'tags')
> >>> canvas.find_withtag('1')

  Thank's for your help,kent! the itemcget method is exactly what I want!
In the first email,I mix the object id and tag,the increasing 
number I talk about is the object id.In the old source,I coded like :
and then use this tagnum as a tag to find the file name in my dictionary.
I had hope that this id would be count form 1 again ,but it won't as
I had found out. A silly mistake I had make!
  now, as your help,I bind the tag and object id in my dictionary:
		icon=self.create_image(10, i*self.dist_y, image=self.fileIcon, anchor=NW,tag=str(i))
and then use itemcget to get the filename.
    k=self.itemcget (CURRENT, "tag")
 I had try find_withtag(l) here and get only one number at the first directory
  if i change to other directory and del tags:
   self.dtag(str(i)) and tag the new items with the same tag
   () is return. 
This is strange!
no matter what, my problem had served thank's alot!


More information about the Tutor mailing list