简体   繁体   English

如何使用多个标签操作 tkinter canvas 对象

[英]How to manipulate tkinter canvas objects with multiple tags

I have many objects in my canvas.我的 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.这将返回 {'tray', 'tt00'} 并使用该组标签创建 object。

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.我还希望能够单独更改每个 object 的颜色,因此每个 object 都有唯一的标签。

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")从: tag = {"tt" + str(n) + str(m), "tray"}到: tag = ("tt" + str(n) + str(m), "tray")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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