Rubyで色々GUI環境試してみてruby-gnome2使うのが一番しっくりきたので
環境
- Mac OS 10.12.6
- Ruby 2.4.1
- ruby-gnome2 3.1.8
bash
mkdir gtk3sample
cd gtk3sample
bundle init
vim Gemfile
Gemfile
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem 'rake'
gem 'gtk3'
bash
bundle install --path vendor/bundle
vim sample.rb
sample.rb
require 'gtk3'
app = Gtk::Application.new('org.gtk.example', :flags_none)
app.signal_connect 'activate' do |application|
window = Gtk::ApplicationWindow.new(application)
window.set_title('Window')
window.set_default_size(200, 200)
label = Gtk::Label.new('Hello, Gtk3')
window.add(label)
window.show_all
end
puts app.run
bash
bundle exec ruby sample.rb