From: Peter Hickman Date: 2002-02-06T19:24:05+09:00 Subject: Re: Progress with Ruby/Tk nagai@ai.kyutech.ac.jp wrote: >For example, >-------------------------------------------------------------- >require 'tk' > >def v_dialog(title, btns, keys) > top = TkToplevel.new{ title(title) } > msg = TkMessage.new(top, keys).pack('side'=>'top', 'fill'=>'x', > 'expand'=>true) > v = TkVariable.new > f = TkFrame.new(top).pack('side'=>'top', 'fill'=>'x', 'padx'=>7, 'pady'=>2) > btns.each_with_index{|btn, idx| > TkButton.new(f, 'text'=>btn, 'command'=>proc{v.value = idx + 1}) \ > .pack('side'=>'top', 'fill'=>'x') > } > top.protocol('WM_DELETE_WINDOW', proc{v.value = 0}) > f.focus > begin > top.grab > v.wait > ensure > top.grab('release') > top.destroy > end > v.to_i >end > >msg = "This is a sample dialog. " + > "It returns clicked button number " + > "based on the order of 'btns' parameter." + > "If the dialog is destroyed by window manager control, returns 0. " + > "To control window size, give 'width' option." + > "If you give options by hash parameter, " + > "they are passed to the message widget on the dialog." >b = TkButton.new{ > text 'disp dialog' > command proc{p v_dialog('dialog sample', ['Yes', 'No', 'Cancel'], > 'text'=>msg, 'width'=>300)} > pack >} >Tk.mainloop >-------------------------------------------------------------- > Once again you ride to the rescue. Thank you