tk_optionMenu in Ruby/Tk


#1

Does anyone know of an example that shows the correct use of
tk_optionMenu in Ruby/Tk? All references I can find deal with popping
up a “normal” menu.

Thanks,
Ken


#2

From: Kenneth McDonald removed_email_address@domain.invalid
Subject: tk_optionMenu in Ruby/Tk
Date: Thu, 4 Dec 2008 01:05:36 +0900
Message-ID: removed_email_address@domain.invalid

Does anyone know of an example that shows the correct use of
tk_optionMenu in Ruby/Tk? All references I can find deal with popping
up a “normal” menu.

Please see line:559–567 of tk/menu.rb.
For example,

require ‘tk’

parent = Tk.root
v = TkVariable.new
TkLabel.new(parent, :textvariable=>v).pack
TkOptionMenubutton.new(parent, v, *%w(foo bar baz hoge fuga)).pack

other style of arguments

TkOptionMenubutton.new(:parent=>parent, :variable=>v,
:values=>%w(FOO BAR BAZ HOGE FUGA)).pack
Tk.mainloop

However, 2nd style doesn’t work because of a bug of tk/menu.rb.
Please use the following patch. I’ll commit it to ruby-svn.

Index: menu.rb

— menu.rb (revision 20349)
+++ menu.rb (working copy)
@@ -569,7 +569,7 @@
keys = _symbolkey2str(keys)

 parent = nil
  • if args[0].kind_of?(TkWindow) || args[0] == nil
  • if !args.empty? && (args[0].kind_of?(TkWindow) || args[0] == nil)
    keys.delete(‘parent’) # ignore
    parent = args.shift
    else
    @@ -577,7 +577,7 @@
    end

    @variable = nil

  • if args[0].kind_of?(TkVariable) || args[0] == nil
  • if !args.empty? && (args[0].kind_of?(TkVariable) || args[0] == nil)
    keys.delete(‘variable’) # ignore
    @variable = args.shift
    else

#3

Thanks Hidetoshi!

Ken