is GUI a weak point?

G

greg.rb

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]
 
B

Bret Pettichord

These days most people use the web for their GUI's. Have you considered
this? It doesn't have to be a web app per se. Ruby has lots of good
options in this area.
 
H

Hidetoshi NAGAI

From: "greg.rb" <[email protected]>
Subject: is GUI a weak point?
Date: Wed, 5 Apr 2006 05:23:59 +0900
Message-ID: said:
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.

I couldn't understand what you want to ask.
Although the following is one of the samples rewriting yours,
it may not be able to answer your question.
===================================================================
require 'tk'

cash_locs=['NONE','NY1','NY2','NJ1','ETC.']

#--------------------------------
# callback function

def put_picked_value(s)
puts 'USER PICKED: ' + s
end

#--------------------------------
# GUI part

Tk.root.title 'PICK LOCATION'

TkButton.new:)text=>'Quit',
:command=>proc{exit}).pack:)side=>:bottom, :fill=>:x)

f = TkFrame.new.pack:)fill=>:both, :expand=>true)

list = TkListbox.new(f)
list.yscrollbar(TkScrollbar.new(f).pack:)side=>:right, :fill=>:y))
list.pack:)side=>:left, :fill=>:both, :expand=>true)

list.insert:)end, *cash_locs)

list.bind('ButtonPress-1',
proc{|y| put_picked_value(list.get(list.nearest(y))) },
'%y')

Tk.mainloop()
===================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top