From: nagai@... Date: 2003-01-07T12:04:45+09:00 Subject: Re: learning ruby and tk Hi, From: Ferenc Engard Subject: learning ruby and tk Date: Tue, 7 Jan 2003 08:22:43 +0900 Message-ID: <3E1A0E91.E0061528@all.hu> > I am getting inside tcltk.rb. I have a question with callbacks: how can > I pass parameters to a non-bind callback? E.g., I have a proc which can > handle many button's click if I could pass a parameter that which button > was pressed (for example). And I do not want to write as many procs as > many buttons I have. It would be the best if I do not need to write as > many callbacks either, i.e., I could pass the parameters where I create > the button widget. Probably, nobody maintains tcltk.rb. Why don't you use tk.rb? Isn't the following script enough for you? ---------------------------------------------- #!/usr/bin/env ruby require 'tk' param = '' cmd = proc{|arg| p arg; param = arg} TkButton.new(nil, 'text'=>'quit', 'command'=>proc{exit}).pack('fill'=>'x') TkButton.new(nil, 'text'=>'print', 'command'=>proc{p param}).pack('fill'=>'x') TkButton.new(nil, 'text'=>'foo', 'command'=>proc{cmd.call([0,'foo'])}).pack('fill'=>'x') ['bar', 'baz', 'hoge', 'huga'].each_with_index{|n,i| TkButton.new(nil, 'text'=>n){ bind('ButtonRelease-1', cmd, "%W (%x,%y) #{i+1} #{n}") pack('fill'=>'x') } } Tk.mainloop ---------------------------------------------- -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)