DEV Community

kojix2
kojix2

Posted on

1 2

Ruby/GTK3 - Button

gem install gtk3

Button

Alt Text

"Click me" button was clicked
"Open" button was clicked
Closing application

require 'gtk3'

class ButtonWindow < Gtk::Window
  def initialize
    super
    set_title 'Button Demo'
    set_border_width 10

    hbox = Gtk::Box.new(:horizontal, 6)
    add(hbox)

    button = Gtk::Button.new(label: 'Click Me')
    button.signal_connect('clicked') { on_click_me_clicked }
    hbox.pack_start(button)

    button = Gtk::Button.new(mnemonic: '_Open')
    button.signal_connect('clicked') { on_open_clicked }
    hbox.pack_start(button)

    button = Gtk::Button.new(mnemonic: '_Close')
    button.signal_connect('clicked') { on_close_clicked }
    hbox.pack_start(button)
  end

  def on_click_me_clicked
    puts '"Click me" button was clicked'
  end

  def on_open_clicked
    puts '"Open" button was clicked'
  end

  def on_close_clicked
    puts 'Closing application'
    Gtk.main_quit
  end
end

win = ButtonWindow.new
win.signal_connect('destroy') { Gtk.main_quit }
win.show_all
Gtk.main
Enter fullscreen mode Exit fullscreen mode

Python version

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more