我对以下代码有点麻烦 - 无论我尝试什么,当我使用标签元组时,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)))
任何帮助都表示赞赏,甚至是想法或链接!
谢谢。
答案 0 :(得分:2)
是什么让你认为你可以将一组标签传递给canvas.coords
?
您可以在effbot.org,The New Mexico Tech website和Tk Manual中阅读,也可以传递ID或标记。然后它将返回第一个匹配项的坐标,或者您可以将新坐标传递给它。
标签主要用于在同一标签下将对象组合在一起。您的行具有多个标记这一事实意味着可以使用任何这些标记找到它。我不知道搜索标签组合的任何方法。如果您想查找一个特定对象,请为其指定一个唯一标记或使用它的ID。