From: jfn@... (Jeremy Nelson) Date: 2001-02-16T04:10:03+09:00 Subject: [ruby-talk:10925] Re: Ruby/Tk Grid Geometry Example jkaurin wrote: >All my attempts with grid geometry and Ruby/Tk have met with failure. Does >anyone have a small example they could post? Something like a change >password dialog box ... some fields in a groove frame in the top window ... [reformatted for fixed-width fonts] >_____________________________________________________ >| _____________________________________________ | >| | ________________ | | >| | Old Password: |_______________| | | >| | ________________ | | >| | New Password: |________________| | | >| | ________________ | | >| | New Password Again: |________________| | | >| |__________________________________________ | | >|___________________________________________________| I'm not sure if you're actually trying to create the above dialog, or if you're just trying to learn grid; I'm assuming you're trying to create the above dialog. Yoo can create the above dialog pretty easily using 'pack'. If you're actually trying to learn grid, let me know. I posted an example in Message-ID: <94t43v$kbb$1@bob.news.rcn.net> (Subject: [SOLUTION] Re: Ruby/Tk -- Creating a class with Labels and Buttons that talk to each other) that you can feel free to re-use if it is helpful. =) --- snip --- require 'tk' class TkObject def focusNext tk_call 'focus', tk_call 'tk_focusNext', @path end def focusPrev tk_call 'focus', tk_call 'tk_focusPrev', @path end end def new_password_widget(parent, label, input_tkvar) x = TkFrame.new(parent) { pack("side"=>"top") } TkLabel.new(x) { text label width 20 justify "right" pack ("padx"=>4, "pady"=>4, "side"=>"left") } v = TkEntry.new(x) { textvariable input_tkvar width 20 show '*' foreground "black" background "white" pack ("padx"=>2, "pady"=>2, "side"=>"right") } v.bind("Return") { v.focusNext } v.bind("KP_Enter") { v.focusNext } v end def password_dialog (parent, proc) tl = TkToplevel.new(parent) frame = TkFrame.new(tl) { borderwidth 4 relief "groove" pack("side"=>"top") } old_password_var = TkVariable.new() new_password_widget(frame, "Old Password:", old_password_var) new_password_var = TkVariable.new() new_password_widget(frame, "New Password:", new_password_var) new_password_again_var = TkVariable.new() y = new_password_widget(frame, "New Password Again:", new_password_again_var) ["Return", "KP_Enter", "Tab"].each { |x| y.bind(x) { proc.call(old_password_var.value, new_password_var.value, new_password_again_var.value) tl.destroy } } end mw = TkRoot.new proc = Proc.new { |old, new, newagain| if (new == newagain) puts("Password accepted") else puts("Password not accepted") end } password_dialog(mw, proc) Tk.mainloop --- snip here --- Jeremy