0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby/GTK3 - SpinButton

Posted at

gem install gtk3

SpinButton

Gtk.SpinButtonでは2つの矢印のいずれかをクリックして、表示されている値を増減する。直接値を入力することもできる。

image.png

require 'gtk3'

class SpinButtonWindow < Gtk::Window

  attr_accessor :spinbutton

  def initialize
    super
    set_title "SpinButton Demo"
    set_border_width 10

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

    adjustment = Gtk::Adjustment.new(0, 0, 100, 1, 10, 0)
    @spinbutton = Gtk::SpinButton.new(adjustment)
    hbox.pack_start(spinbutton)

    check_numeric = Gtk::CheckButton.new("Numeric")
    check_numeric.signal_connect("toggled"){|b| on_numeric_toggled b}
    hbox.pack_start(check_numeric)

    check_ifvalid = Gtk::CheckButton.new("If Valid")
    check_ifvalid.signal_connect("toggled"){|b| on_ifvalid_toggled b}
    hbox.pack_start(check_ifvalid)
  end

  def on_numeric_toggled(button)
    spinbutton.set_numeric(button.active?)
  end

  def on_ifvalid_toggled(button)
    policy = if button.active?
               Gtk::SpinButtonUpdatePolicy::IF_VALID
             else
               Gtk::SpinButtonUpdatePolicy::ALWAYS
             end
    spinbutton.set_update_policy(policy)

  end
end

win = SpinButtonWindow.new
win.signal_connect("destroy"){ Gtk.main_quit }
win.show_all
Gtk.main
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?