1

I have started to learn the ropes of Gtk in Ruby, and I have built this very simple program:

require 'gtk2'
include Gtk

Gtk.init

window = Window.new
window.show
window.set_title "// Edit //"
window.signal_connect "destroy" do 
    Gtk.main_quit
end

box = VBox.new 10 

text = Entry.new
text.set_text "Enter your name"
box.pack_start text

button = Button.new "Go!"
button.signal_connect "clicked" do 
    puts "Hello "+text.get_text()+"!"
end
box.pack_start button

window.add box
window.show_all

Gtk.main

However when I press the button, the program outputs an error saying this:

test.rb:21:in `block in <main>': undefined method `get_text' for # <Gtk::Entry:0x20be2d8 ptr=0x13831d0>
Did you mean?  set_text
     from test.rb:28:in `main'
     from test.rb:28:in `<main>'

In that case, how do I retrieve text from the Entry widget in GTK? Thanks in advance.

Logan Darby
  • 145
  • 16

1 Answers1

2

The name of the method you need is text. For instance,

my_entry = Entry.new
puts my_entry.text