2010-12-11 9 views
2

J'essaye de lier un argument supplémentaire opt aux boutons radio suivants ci-dessous. J'essaie de faire en sorte que lorsque WSRB_UD est déclenché, je peux savoir quel radiobutton l'a déclenché. Comment je vais à ce sujet?Passer des arguments supplémentaires avec Tkinter Bindings

Snippet:

 self.WS.SW.SearchFrame = [] 
     self.WS.SW.SearchRB = [] 

     self.WS.RBvar = Tkinter.IntVar() 

     i = 0 
     while i < 6 : 

      Frame = Tkinter.Frame(self.WS.SW.OptFrame, width=125, height=22, bd=1, 
              bg=self.WSbg) 
      Frame.grid(column=0, row=4 + i) 
      Frame.grid_propagate(0) 

      self.WS.SW.SearchFrame.append(Frame) 


      RB = Tkinter.Radiobutton(self.WS.SW.SearchFrame[i], value=i, 
           variable=self.WS.RBvar, indicatoron=0, font=self.WSfo, 
           fg=self.WSfg, activeforeground=self.WSfg, bg=self.WSbg, activebackground=self.WSbg, 
           selectcolor=self.WSbg, bd=self.WSbw) 
      RB.grid() 
      RB.bind("<Enter>", self.WSRB_UD, i) 
      print i 

      self.WS.SW.SearchRB.append(RB) 

      i = i + 1 

     self.QuickLinkList= [] 
     self.WS_timer_count = 0 

    def WSRB_UD(self, event, opt): 
     print self.WS.RBvar.get() 
+0

duplication possible de [tkinter: spécification d'arguments pour une fonction appelée lorsque vous appuyez sur un bouton] (http://stackoverflow.com/questions/2297336/tkinter-specifying-arguments-for-a-function-thats-called -quand-vous-appuyez-a-butto) –

Répondre

3

Vous pouvez utiliser lambda pour définir une fonction partielle anonyme:

RB.bind("<Enter>", lambda event: self.WSRB_UD(event, i)) 

Vous pouvez également utiliser functools.partial si vous ne voulez pas la syntaxe lambda.

Questions connexes