Hi, From: Sven Bauhan <svenbauhan / web.de> Subject: [Ruby/Tk] Cannot close window Date: Fri, 28 Jan 2005 07:55:53 +0900 Message-ID: <35t9qlF4o3ho1U1 / individual.net> > class NotifyDialog > def initialize > @root = TkRoot.new { title "Notification" } > TkLabel.new { > text "Message" > pack > } > TkButton.new { > text "Close" > command proc { @root.iconify() } > pack > } > end > end The block given to TkButton.new method is evaluated by instance_eval. So, in the block, self is the created button widget object. That is the reason of why @roo is undefined. solution 1: use a local variable ------------------------ def initialize root = @root = TkRoot.new { title "Notification" } TkLabel.new { text "Message" pack } TkButton.new { text "Close" command proc { root.iconify() } pack } end ------------------------ solution 2: call command method at out of the block ------------------------ b = TkButton.new { text "Close" pack } b.command{ @root.iconify } # == b.command(proc{@root.iconify}) ------------------------ or ------------------------ TkButton.new { text "Close" pack }.command{ @root.iconify } ------------------------ solution 3: use commandline arguments ------------------------ TkButton.new(:text=>'Close', :command=>proc{@root.iconify}).pack ------------------------ -- Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)