greg.rb
4/4/2006 8:20:00 PM
Ruby seems pretty eash to code and understand. However, as a
non-professional programmer, I find GUI the hardest part so far.
GTK didn't work out of the box on windows. It is too bad because it
looked like it would be one of the better GUI choices. I guess I will
have to try FOX.
Any suggestions?
Are there any good examples of getting tk widget data to ruby?
Here is a simple example where I try to build an interface for the user
to pick information which will then be sent to ruby to process.
#example:
require 'tk'
cash_locs=['NONE','NY1','NY2','NJ1','ETC.']
root = TkRoot.new() { title "PICK LOCATION" }
bar = TkScrollbar.new(root).pack('side'=>'right', 'fill'=>'y')
fromLoc = TkVariable.new
list = TkListbox.new(root){}
list.pack('side'=>'left', 'fill'=>'both', 'expand'=>true)
list.yscrollbar(bar)
cash_locs.each { |loc|
list.insert('end', loc)
}
button = TkButton.new(root) {
text 'OK'
command proc {fromLoc.value=list.curselection(),TkRoot.new.destroy}
}
button.pack()
TkButton.new(nil, 'text'=>'Quit',
'command'=>proc{TkRoot.new.destroy}).pack('fill'=>'x')
Tk.mainloop()
puts 'USER PICKED: '+cash_locs[fromLoc.value.to_i]