Tkinter canvas.coords 方法不适用于元组

Tkinter canvas.coords method not working with tuple

我在使用以下代码时遇到了一些问题 - 无论我尝试什么,当我使用标签元组时,坐标函数 returns 都是一个空列表。

def drop_line(self, event):
    """
    Function to call when the mouse is released. Creates a permanent bond between people.
    """
    self.delete_temporary()
    person = self.canvas.find_enclosed(event.x - self.people_size_var.get(),
                                       event.y - self.people_size_var.get(),
                                       event.x + self.people_size_var.get(),
                                       event.y + self.people_size_var.get())

    # Writing friendships to dictionary.
    try:
        Link.person_name = self.canvas.gettags(person)
        Link.friends_dictionary[Link.person_name[0]] = (Link.friend_name[0] + "," +
                                                        Link.friends_dictionary[Link.person_name[0]])
        Link.friends_dictionary[Link.friend_name[0]] = (Link.person_name[0] + "," +
                                                        Link.friends_dictionary[Link.friend_name[0]])
        line = self.canvas.create_line(self.pos_x, self.pos_y, event.x, event.y, activefill="red", smooth=True,
                                       fill="black",width=self.edge_width_var.get(),
                                       tags=("permanent", Link.person_name[0], Link.friend_name[0]))


        # My problem is here :( Can't get the last 2 prints to work

        print(self.canvas.gettags(line))
        print(("permanent", Link.person_name[0], Link.friend_name[0]))
        print(self.canvas.coords(("permanent", Link.person_name[0], Link.friend_name[0])))
        print(self.canvas.coords(self.canvas.gettags(line)))

感谢任何帮助,甚至是想法或链接!

谢谢。

是什么让您认为可以将标签元组传递给 canvas.coords
正如您在 effbot.org, The New Mexico Tech website and in the Tk Manual 上看到的那样,您可以传递一个 id 或一个标签。然后它将 return 第一个匹配项的坐标,或者您可以将新坐标传递给它。

标签主要用于将对象分组在同一标签下。您的线路有多个标签这一事实仅意味着可以使用这些标签中的任何一个找到它。我不知道有什么方法可以搜索标签组合。如果你想找到一个特定的对象,给它一个唯一的标签或使用它的 id。