[Tutor] Tkinter, how to retrieve information about an object on canvas
Axel Wegen
axel.wegen at gmail.com
Thu Nov 15 05:44:13 CET 2012
Matheus Soares da Silva <matheusoares at poli.ufrj.br> writes:
> Hello, I would like to be able to get information from a Tkinter
> canvas object. (color, width, tags, root points, etc),
You can get the information of an object on the canvas by passing its id
to certain canvas methods like itemconfigure:
>>> c = Canvas()
>>> c.pack()
>>> c.create_rectangle(30,30,90,90,fill="black")
1
>>> c.itemconfigure(1)
Should yield a dictionary containing the options of the rectangle.
> the widget is returned as a tuple by the find_overlapping method.
Utilising find_overlapping you will get a tuple of multiple object-ids.
To get a single object you index into the tuple:
>>> c.find_overlapping(31,31,33,33)
(1,)
>>> c.itemconfigure(c.find_overlapping(31,31,33,33)[0])
btw. there is also a tkinter specific mailing-list:
tkinter-discuss at python.org
--
Axel Wegen
More information about the Tutor
mailing list