From: Kenneth McDonald Date: 2008-12-04T05:56:35+09:00 Subject: Re: tk_optionMenu in Ruby/Tk Thanks Hidetoshi! Ken On Dec 3, 2008, at 2:48 PM, Hidetoshi NAGAI wrote: > From: Kenneth McDonald > Subject: tk_optionMenu in Ruby/Tk > Date: Thu, 4 Dec 2008 01:05:36 +0900 > Message-ID: <01353FAB-8102-4C41-B542-6540128B5379@sbcglobal.net> >> 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 > > -- > Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) >