mieki256's diary



2026/02/21() [n年前の日記]

#3 [ruby] ruby-gtk4/ruby-gtk3をRuby 3.4.8 x64にインストール

Windows11 x64 25H2 + Ruby 3.4.8 x64 (Rubyinstaller版)で、gtk4 (ruby-gtk4) がインストールできそうか試してみた。

_gtk4 | RubyGems.org | コミュニティのgemホスティングサービス
_ruby-gnome/ruby-gnome: A set of bindings for the GNOME libraries to use from Ruby.

Ruby 2.3.8 x64にインストール :

gtk4 は、以下のパッケージが必要になる模様。

> gem install gtk4

Fetching gobject-introspection-4.3.5.gem
Fetching glib2-4.3.5.gem
Fetching graphene1-4.3.5.gem
Fetching cairo-1.18.4.gem
Fetching gdk_pixbuf2-4.3.5.gem
Fetching gio2-4.3.5.gem
Fetching cairo-gobject-4.3.5.gem
Fetching pango-4.3.5.gem
Fetching atk-4.3.5.gem
Fetching gtk4-4.3.5.gem
Fetching gdk4-4.3.5.gem
Fetching gsk4-4.3.5.gem
...

Done installing documentation for glib2, gobject-introspection, graphene1, cairo, cairo-gobject, pango, gio2, gdk_pixbuf2, gdk4, gsk4, atk, gtk4 after 7 seconds
12 gems installed

gtk4 4.3.5 をインストールできたっぽい?

サンプル :

ruby-gtk4 を使ったサンプルをAI(Google Gemini)に提示して貰った。Hello World と表示しつつ、ボタンをクリックしたらメッセージダイアログを表示する。動いてくれた。

01_hello_gtk4.rb
require "gtk4"

application = Gtk::Application.new("jp.example.hello", :default_flags)

application.signal_connect "activate" do |app|
  window = Gtk::ApplicationWindow.new(app)
  window.set_title("Ruby GTK4 Sample")
  window.set_default_size(300, 200)

  box = Gtk::Box.new(:vertical, 10)
  box.set_margin_top(20)
  box.set_margin_bottom(20)
  box.set_margin_start(20)
  box.set_margin_end(20)

  label = Gtk::Label.new("Hello World")
  box.append(label)

  label2 = Gtk::Label.new("Use : ruby-gtk4")
  box.append(label2)

  button = Gtk::Button.new(label: "Push me")
  button.signal_connect "clicked" do
    dialog = Gtk::MessageDialog.new(
      parent: window,
      flags: :modal,
      type: :info,
      buttons: :ok,
      message: "Hello",
    )
    dialog.signal_connect("response") { dialog.destroy }
    dialog.show
  end
  box.append(button)

  window.set_child(box)
  window.present
end

puts "Starting GTK4 Application..."
application.run([$0] + ARGV)

rub-gtk3のインストール :

Windows11 x64 25H2 + Ruby 3.4.8 x64 (Rubyinstaller版)に、ruby-gtk3 (gtk3) をインストールしてみた。

_gtk3 | RubyGems.org | コミュニティのgemホスティングサービス

gtk4 をインストールしてから、直後に gtk3 をインストールした。必要なパッケージは gtk4 の段階でインストールされたように見える。

> gem install gtk4

> gem install gtk3

Fetching gtk3-4.3.5.gem
Fetching gdk3-4.3.5.gem
Temporarily enhancing PATH for MSYS/MINGW...
Installing required msys2 packages: mingw-w64-ucrt-x86_64-gtk3
Building native extensions. This could take a while...
Successfully installed gdk3-4.3.5
Building native extensions. This could take a while...
Successfully installed gtk3-4.3.5
Parsing documentation for gdk3-4.3.5
Installing ri documentation for gdk3-4.3.5
Parsing documentation for gtk3-4.3.5
Installing ri documentation for gtk3-4.3.5
Done installing documentation for gdk3, gtk3 after 1 seconds
2 gems installed

gtk3 4.3.5 がインストールされた。手元にあったサンプルも動いてくれた。

ただ、Ruby 3.4.8 x64 (64bit版)ではなく、Ruby 3.4.8 x86 (32bit版) でインストールを試した時はエラーが出まくった…。x64版なら上手く行くのかもしれない。

以上です。

過去ログ表示

Prev - 2026/02 -
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28

カテゴリで表示

検索機能は Namazu for hns で提供されています。(詳細指定/ヘルプ


注意: 現在使用の日記自動生成システムは Version 2.19.6 です。
公開されている日記自動生成システムは Version 2.19.5 です。

Powered by hns-2.19.6, HyperNikkiSystem Project