绑定鼠标光标事件

2024-07-07 09:06:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我在使用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) 

正如你们所看到的,我并没有正确地合并这个,它不能计算。关于我可能做错什么有什么帮助吗


Tags: ofnameselfmaster名称eventinitbind