tk_optionMenu in Ruby/Tk

  • Thread starter Kenneth McDonald
  • Start date
K

Kenneth McDonald

[Note: parts of this message were removed to make it a legal post.]

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
 
H

Hidetoshi NAGAI

From: Kenneth McDonald <[email protected]>
Subject: tk_optionMenu in Ruby/Tk
Date: Thu, 4 Dec 2008 01:05:36 +0900
Message-ID: said:
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
 
K

Kenneth McDonald

Thanks Hidetoshi!

Ken


From: Kenneth McDonald <[email protected]>
Subject: tk_optionMenu in Ruby/Tk
Date: Thu, 4 Dec 2008 01:05:36 +0900
Message-ID: said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top