Btk project Download

How to use

Example:Hello World

#!/usr/bin/env ruby
=begin
Tutorial equal http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk-helloworld
=end
require 'rubygems'
require 'btk'

# w will call border_width= or set_border_width with parameter 10
Btk.Window :border_width=>10 do|w|

        #alias of signal_connect('delete_event')
        w.sig_delete_event do
                puts "delete event occurred"
                false
        end

        #alias of signal_connect('destroy')
        w.sig_destroy do
                puts "destroy event occurred"
                Gtk.main_quit
        end

        # Button will add to w automatically
        w.Button "Hello World" do|btn|
                btn.sig_clicked do
                        puts "Hello World"
                end
        end
        w.show_all
end
Gtk.main

Example:Layout

require 'rubygems'
require 'btk'
include Gtk

# the hash option will call set_[key](...) except :pack
# w.set_default_size(640,400)
# w.set_window_position(Window::POS_CENTER)
Btk.Window :default_size=>[640,400],:window_position=>Window::POS_CENTER do|w|
        w.sig_destroy do
                Gtk.main_quit
        end

        w.VBox do|vbox|
                #equal
                #sw.set_policy(POLICY_AUTOMATIC,POLICY_AUTOMATIC)
                #vbox.pack_start(sw)
                vbox.ScrolledWindow :policy=>[POLICY_AUTOMATIC,POLICY_AUTOMATIC] do|sw|
                        sw.TextView
                end

                # :pack=>false will make vbox call vbox.pack_start(hbox,false)
                vbox.HBox :pack=>false do|hbox|
                        hbox.Button "OK",:pack=>false
                        hbox.Button "QUIT",:pack=>false do|btn|
                                btn.sig_clicked do
                                        w.destroy
                                end
                        end
                end
        end
        w.show_all
end
Gtk.main