March 5, 2018

Ruby GTK3: the basics

Here is the script basic.rb

#!/usr/bin/ruby

require 'gtk3'

Gtk::init()

win = Gtk::Window.new()
win.set_title ( "basic" )

win.signal_connect ( 'delete_event' ) { false }
win.signal_connect ( 'destroy' ) { Gtk.main_quit }

win.show_all

Gtk.main
# THE END

The above is a pretty minimal skeleton for a ruby GTK3 script.

Take note of the two lines of code that call signal_connect(). Here we are leveraging a Ruby block to set up an event handler in a nice clean way.


Feedback? Questions? Drop me a line!

Tom's Computer Info / [email protected]