From: Hidetoshi NAGAI Date: 2007-03-16T23:09:41+09:00 Subject: Re: Binding or executing a command with a TkOptionMenubutton From: Alex DeCaria Subject: Binding or executing a command with a TkOptionMenubutton Date: Fri, 16 Mar 2007 22:13:22 +0900 Message-ID: > I've tried the following simple example which should print the value of > the selection, but it only works if the mouse is directly over the > button itself, and not over the expanded options. > > Any ideas how to do this? For example, ----------------------------------------------------------------- require 'tk' root = TkRoot.new.title("MenuOptionbutton") list = ["1", "2", "3", "4", "5"] var = TkVariable.new button = TkOptionMenubutton.new(root,var,*list).pack menu = button.menu menu.bind('ButtonRelease-1', '@%y'){|y| value = menu.entrycget(y, :value) print var, ' -> ', value, "\n" } # OR, #menu.bind('ButtonRelease-1', '%y'){|y| # value = menu.entrycget("@#{y}", :value) # print var, ' -> ', value, "\n" #} Tk.mainloop ----------------------------------------------------------------- -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)