简体   繁体   中英

How to manipulate tkinter canvas objects with multiple tags

I have many objects in my canvas. They all share one tag in common, plus they all have a unique tag.

tag = {"tt" + str(n) + str(m), "tray"}

I collect these tags as per bellow

tags = create_tags.tray_pocket_tag[n][m]

This returns me {'tray', 'tt00'} and an object is created with that set of tags.

canvas.create_rectangle(x1, y1, x2, y2, outline="black", fill="red", tags=tags)
root.update()

Now I wanna be able to move all objects that share a tag "tray" at the same time to a different location. I'm trying that like this

canvas.move("tray", 0, new_y_coord)
root.update()

I also wanna be able of changing the color of each object individually, hence the unique tag each object has.

I try this

tag = str(tags - "tray")
canvas.itemconfigure(tag, outline="black", fill="gray")
root.update()

But no success. Ideas?

Solution:

From: tag = {"tt" + str(n) + str(m), "tray"} To: tag = ("tt" + str(n) + str(m), "tray")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM