Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Binding or executing a command with a TkOptionMenubutton

Reply
Thread Tools

Binding or executing a command with a TkOptionMenubutton

 
 
Alex DeCaria
Guest
Posts: n/a
 
      03-16-2007
I want my program to execute a command whenever a new selection is made
from a TkOptionMenubutton. The -command option isn't allowed with
TkOptionMenubuttons, so I've been experimenting with various bindings,
but can't find an appropriate binding event.

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?

#------------------------------------
require 'tk'
root = TkRoot.new.title("MenuOptionbutton")

list = ["1", "2", "3", "4", "5"]
var = TkVariable.new
button = TkOptionMenubutton.new(root,var,*list).pack
button.bind('ButtonRelease-1') do
print var, "\n"
end

Tk.mainloop

#--------------------------------------------

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Hidetoshi NAGAI
Guest
Posts: n/a
 
      03-16-2007
From: Alex DeCaria <(E-Mail Removed)>
Subject: Binding or executing a command with a TkOptionMenubutton
Date: Fri, 16 Mar 2007 22:13:22 +0900
Message-ID: <(E-Mail Removed)>
> 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 ((E-Mail Removed))

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView binding - how to stop initial binding Amit ASP .Net 6 10-24-2006 08:06 AM
pywin32 COM sort in Excel (late binding fails, early binding works) (+py2exe) kogrover@gmail.com Python 2 10-20-2006 04:08 PM
Complex data binding question, binding child objects of a custom collection. JcFx ASP .Net Datagrid Control 0 06-01-2005 04:01 PM
Data Binding - using inline code vs. functions vs. straight binding Jordan ASP .Net 2 02-10-2004 08:32 PM
value binding and function binding Vivek Nallur Ruby 0 09-25-2003 02:52 AM



Advertisments