1#!/usr/bin/env ruby 2require 'tk' 3 4TkLabel.new(:text=>"Please click the bottom frame").pack 5 6f = TkFrame.new(:width=>400, :height=>100, :background=>'yellow', 7 :relief=>'ridge', :borderwidth=>5).pack 8 9# TkPack.propagate(f, false) # <== important!! 10f.pack_propagate(false) # <== important!! 11 12list = (1..3).collect{|n| 13 TkButton.new(f, :text=>"button#{'-X'*n}"){ 14 command proc{ 15 puts "button#{'-X'*n}" 16 self.unpack 17 } 18 } 19} 20 21list.unshift(nil) 22 23f.bind('1', proc{ 24 w = list.shift 25 w.unpack if w 26 list.push(w) 27 list[0].pack(:expand=>true, :anchor=>:center) if list[0] 28 }) 29 30Tk.mainloop 31