开发者

ruby gtk installation problem on Fedora

I recently wanted to install Ruby bindings for GTK on my Fedor开发者_高级运维a 15 box. I installed all the packages with yum (ruby-gtk2, ruby-gtk2-devel, all that), and I get a NameError when trying to do a simple Hello World GUI app in Ruby. Here's the code:

require 'gtk'

window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
button = Gtk::Button.new("Hello World")

window.set_title("Hello Ruby")
window.border_width(10)

# Connect the button to a callback.
button.signal_connect('clicked') { puts "Hello Ruby" }

# Connect the signals 'delete_event' and 'destroy'
window.signal_connect('delete_event') {
    puts "delete_event received"
    false
}
window.signal_connect('destroy') {
    puts "destroy event received"
    Gtk.main_quit
}

window.add button
window.show_all
Gtk.main


First of all, you want to pull in gtk2 not gtk so change your require to this:

require 'gtk2'

Then, from the fine manual:

Gtk::Window.new(type = Gtk::Window::TOPLEVEL)

Creates a new Gtk::Window, which is a toplevel window that can contain other widgets.

So you don't actually need to specify the type when you want a toplevel window but if you want to specify the type, then you want to use the Gtk::Window::TOPLEVEL constant not Gtk::WINDOW_TOPLEVEL:

window = Gtk::Window.new(Gtk::Window::TOP_LEVEL)

That pretty much exhausts my (current) knowledge of the Ruby Gtk bindings but hopefully it will get you moving the right direction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜