/GTK3 - SpinButton

6087 단어 GTK3gtkRuby
gem install gtk3

SpinButton


Gtk.SpinButon에서 두 개의 화살표 중 하나를 클릭하여 표시되는 값을 늘립니다.값을 직접 입력할 수도 있습니다.
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
  • Python version
  • 좋은 웹페이지 즐겨찾기