I'm trying to bind an extra argument opt to the following radiobuttons below. I'm trying to make it so that when WSRB_UD is triggered I can know which radiobutton triggered it. How do I go about this?
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开发者_C百科.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()
You can use lambda to define an anonymous partial function:
RB.bind( "<Enter>", lambda event: self.WSRB_UD(event, i) )
You could also use functools.partial
if you don't like the lambda syntax.
精彩评论