将名称绑定到形状时遇到问题

时间:2016-04-07 20:40:55

标签: python tkinter tkinter-canvas

我创建了一个带有地图名称的数组--4个名字,我使用这些名称作为参数,用于在画布上命名矩形形状。现在我想用矩形名称映射这些数组名称,以便当用户单击矩形时,它将生成我已分配的名称。 我试图将mapNames数组名称绑定到矩形但是无法做到这一点,遇到StringVar()问题并更改值以匹配不同的矩形,任何帮助都会受到赞赏吗?

  class Viewer(Frame):

    def __init__(self, master = None):
    Frame.__init__(self, master)
   ........lines of code
    self.canvas.bind("<Button-1>", self.bind)
    self.var = StringVar()

   def bind(self, event):
      self.x, self.y = event.x, event.y
      for names in self.mapNames:
      self.var = self.var.set(self.names) 
      return self.var

     ##Trying to set the StringVar as the names in array Mapnames so         
       that when user clicks, the Map names that is the same as the 
       names that were assigned to the rectangles will print.

0 个答案:

没有答案