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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay