DEV Community

kojix2
kojix2

Posted on

3 1

Ruby/GTK3 - RaddioButton

gem install gtk3

RadioButton

Radio button allows the user to choose only one option.

raddio button

require 'gtk3'

class RadioButtonWindow < Gtk::Window
  def initialize
    super
    set_title 'RadioButton Demo'
    set_border_width 10

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

    button1 = Gtk::RadioButton.new(label: 'Button 1')
    button1.signal_connect('toggled') { |b| on_button_toggled b, 1 }
    hbox.pack_start(button1)

    button2 = Gtk::RadioButton.new(member: button1, label: 'Button 2')
    button2.signal_connect('toggled') { |b| on_button_toggled b, 2 }
    hbox.pack_start(button2)

    button3 = Gtk::RadioButton.new(member: button1, label: 'B_utton 3',
                                   use_underline: true)
    button3.signal_connect('toggled') { |b| on_button_toggled b, 3 }
    hbox.pack_start(button3)
  end

  def on_button_toggled(button, name)
    state = button.active? ? 'on' : 'off'
    puts "Button #{name} was turned #{state}"
  end
end

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

output

Button 1 was turned off
Button 2 was turned on
Button 2 was turned off
Button 1 was turned on
Button 1 was turned off
Button 3 was turned on

The options member and use_underline are defined here.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Retry later
Retry later