From: Enrico Schwass <deckard73 / freenet.de>
Subject: Re: rubytk dialog
Date: Wed, 8 Jun 2005 02:40:55 +0900
Message-ID: <42A5DC87.5070702 / freenet.de>
> There is a some unneccessary code in it especcially the pack options are 
> just for experiments

Hmmm.....
If I were you, reuse the created ValueEntry object. 
For example, 
-------------------------------------------------------
require 'tk'

class ValueEntry
  def initialize
    @top = TkToplevel.new(:borderwidth=>1, :relief=>:raised){
      withdraw
      bind('Visibility'){self.raise} # to keep on top
    }

    @label = TkLabel.new(@top, :text=>'').pack(:anchor=>:c)

    @value = TkVariable.new
    @entry = TkEntry.new(@top, :textvariable=>@value).pack

    @answer = ans = TkVariable.new
    TkFrame.new(@top, :borderwidth=>1){|bot|

      TkFrame.new(bot, :borderwidth=>1).pack(:side=>:left, :expand=>true, 
                                             :padx=>10, :pady=>10)

      TkButton.new(bot, :text=>'Accept'){
        bind('ButtonRelease-1'){ ans.bool = true }
      }.pack(:side=>:left, :expand=>true)

      TkButton.new(bot, :text=>'Discard'){
        bind('ButtonRelease-1'){ ans.bool = false }
      }.pack(:side=>:left, :expand=>true)

    }.pack
  end

  def show(window, txt, init)
    @answer.value = ''
    @label.text   = txt
    @value.value  = init

    rx = TkWinfo.rootx(window)
    ry = TkWinfo.rooty(window)

    rh = TkWinfo.height(window)
    rw = TkWinfo.width(window)

    mh = TkWinfo.reqheight(@top) # should be reqheight instead of height
    mw = TkWinfo.reqwidth(@top)  # should be reqwidth instead of width

    @top.geometry("+#{rx+rw/2-mw/2}+#{ry+rh/2-mh/2}")
    @top.deiconify

    Tk.update_idletasks

    @entry.focus

    @top.grab

    @answer.wait

    @top.grab_release
    @top.withdraw

    self.value
  end

  def value
    (@answer.bool)? @value.value: nil
  end

  def destroy
    @top.destroy
  end
end

if $0 == __FILE__
  t = TkText.new.pack
  ve = ValueEntry.new
  TkButton.new(:command=>proc{ p ve.show(t, 'foo', 'bar') }).pack
  Tk.mainloop
end
-------------------------------------------------------
-- 
Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)