From: Enrico Schwass Date: 2005-06-08T02:40:55+09:00 Subject: Re: rubytk dialog Hello There is a some unneccessary code in it especcially the pack options are just for experiments class ValueEntry def initialize(window, txt, init) @answer = TkVariable.new("") rx = TkWinfo.rootx window ry = TkWinfo.rooty window rh = TkWinfo.height window rw = TkWinfo.width window top = TkToplevel.new(window) { relief 'raised' border 1 } top.grab label = TkLabel.new(top) { text txt pack('anchor'=>'c') } @entry = TkEntry.new(top) { pack } @entry.value = init @entry.focus bot = TkFrame.new(top) { border 1 } TkFrame.new(bot) { border 1 pack('side'=>'left', 'expand'=>'yes', 'padx'=>10, 'pady'=> 10) } a = TkButton.new(bot) { text "Accept" pack('side'=>'left', 'expand'=>'yes') } a.bind("ButtonRelease-1") do @answer.value = "Accept" end d = TkButton.new(bot) { text "Discard" pack('side'=>'left', 'expand'=>'yes') } d.bind("ButtonRelease-1") do @answer.value = "Discard" end bot.pack Tk.update mh = TkWinfo.height top mw = TkWinfo.width top nx = rx+rw/2-mw/2 ny = ry+rh/2-mh/2 geom = mw.to_s + 'x'+ mh.to_s + '+' + nx.to_s + '+' + ny.to_s top.geometry(geom) @answer.wait result = @entry.value top.grab(:release) top.destroy # NOTE: this is totally crap if @answer.value == "Accept" return result else return nil end end end