From: Its Me Date: 2004-04-26T12:09:05+09:00 Subject: Re: tk: how to dynamically remove / add widgets? Perfect! Thank you very much. I don't have rdoc documentation working so this is more guesswork that it should be. "Hidetoshi NAGAI" wrote in message > I intend to show that a callback for a widget can control another > widget. In other words, you can pack/unpack some widgets in a > callback procedure. If you hate the frame size is changed when packing > some widgets in the frame, you must set TkPack.propagate to false. > Please see the following sample script, and compare the difference > of propagate mode (true/false). > ----------------------------------------------------------- > #!/usr/bin/env ruby > require 'tk' > > TkLabel.new(:text=>"Please click the bottom frame").pack > > f = TkFrame.new(:width=>400, :height=>100, :background=>'yellow', > :relief=>'ridge', :borderwidth=>5).pack > > TkPack.propagate(f, false) # <== important!! > > list = (1..3).collect{|n| > TkButton.new(f, :text=>"button-#{'X'*n}"){ > command proc{ > puts "button-#{'X'*n}" > self.unpack > } > } > } > > f.bind('1', proc{ > w = list.shift > w.unpack > list.push(w) > list[0].pack(:anchor=>:center) > }) > > Tk.mainloop > ----------------------------------------------------------- > -- > Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) > >