Reputation: 35
I have a bunch of objects interacting with each other. They all draw ovals that constitute representations of themselves on a Tkinter Canvas, and store the representation's Tkinter id as an attribute.
How can I make it so when I click one of the ovals, my program will print the other attributes of the object which that oval represents?
Upvotes: 0
Views: 218
Reputation: 386210
When you click on an item, you can get the canvas item id of the one that was clicked on. You would then use this information to look up the actual object. You can either iterate over all your objects looking for one with the given id, or you can keep a dictionary which maps ids to objects. Once you have the actual object, you can print the other attributes however you want.
Upvotes: 1