Hi, From: MENON Jean-Francois <Jean-Francois.MENON / meteo.fr> Subject: tk troubles Date: Tue, 26 Feb 2002 08:37:01 +0900 Message-ID: <3C7ACA97.1C4895E5 / meteo.fr> > I have some troubles with tk: > when trying to put several windows into a text widget, it seems that > ruby handle only one frame for both, so when I try to close the second > TkTextWindow, my app close entirely: -\ > here is an example (Am I missing something?) Where is an example? > A strange behavior appeared too when trying to use multiple > checkbuttons, it seems that they share the same internal variable. Do you really use different TkVariable objects? Please check scope of variables. > Newbie question: how to set a callback when a TkVariable's value is > changed in a TkEntry? Well, here is an example. ------------------------------------------------------------- require 'tk' languages = ['Ruby', 'Perl', 'Python', 'C', 'C++'] TkRoot.new.title 'your languages' f_b = TkFrame.new.pack('side'=>'top', 'fill'=>'x') TkFrame.new.pack('side'=>'top', 'pady'=>5) f_l = TkFrame.new.pack('side'=>'top', 'fill'=>'x') languages.each{|lang| var = TkVariable.new('don\'t use') TkCheckButton.new(f_b, 'text'=>lang, 'anchor'=>'w', 'variable'=>var, 'onvalue'=>'use', 'offvalue'=>'don\'t use') \ .pack('side'=>'top', 'padx'=>10, 'fill'=>'x') l = TkLabel.new(f_l, 'anchor'=>'w', 'text'=>"You #{var.value} #{lang}.") \ .pack('side'=>'top', 'fill'=>'x') var.trace('w', proc{l.text "You #{var.value} #{lang}."}) } other = TkVariable.new('') TkFrame.new(f_b){|f| TkLabel.new(f, 'text'=>'other:').pack('side'=>'left', 'anchor'=>'w') TkEntry.new(f, 'textvariable'=>other, 'width'=>12) \ .pack('side'=>'left', 'anchor'=>'w') pack('side'=>'top', 'padx'=>10, 'fill'=>'x') } msg = TkLabel.new(f_l, 'anchor'=>'w').pack('side'=>'top', 'fill'=>'x') other.trace('w', proc{ lang = other.value if lang == '' msg.text '' else msg.text "You use #{lang}." end }) Tk.mainloop ------------------------------------------------------------- -- Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)