0

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

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)))

任何帮助表示赞赏,甚至是想法或链接!

谢谢你。

4

1 回答 1

2

是什么让您认为您可以将标签元组传递给canvas.coords?
正如您可以在effbot.orgThe New Mexico Tech 网站Tk 手册中阅读的那样,您可以传递 id 或标签。然后它将返回第一个匹配项的坐标,或者您可以将新坐标传递给它。

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

于 2015-03-05T13:57:12.700 回答