绑定鼠标光标事件问题

时间:2016-04-07 12:23:32

标签: python tkinter

我遇到了使用StringVar()控制变量绑定事件(鼠标光标操作)的问题。问题的一部分是我不知道如何将它们合并在一起。

我想要做的是获取我创建的矩形形状的名称并为其指定名称。

   class GraphicMap(Frame):

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

     def attrib(self, graphic):
       self.name = graphic  #name i will assign to rectangle shapes

     ................# lines of code
        ## i have created rectangle shapes on a canvas with different 
                     names, using this method.

       ##now i would like to use this method for when i click on a shape, it 
        presents the self.name i have allocated.

      def binding(self, event):
         self.name = event.name
         return event.name

      def setContent(self):
        self.content.set(self.name) 

正如您所看到的,我没有正确地合并它,它不会计算。对我可能做错的任何帮助?

1 个答案:

答案 0 :(得分:0)

您绑定到self.bind,但尚未定义self.bind。由于您继承自Frameself.bind是标准bind方法

相关问题