1#!/usr/bin/env ruby 2require 'tk' 3require 'tkextlib/iwidgets' 4 5class Spinner_demo < TkWindow 6 Months = %w(January February March April May June July August September October November December) 7 8 def block_input(c) 9 false 10 end 11 12 def spin_month(step) 13 index = Months.index(@spinner.get) + step 14 index = 11 if index < 0 15 index = 0 if index > 11 16 17 @spinner.value = Months[index] 18 end 19 20 def initialize(parent=nil) 21 @spinner = Tk::Iwidgets::Spinner.new(parent, :labeltext=>'Month : ', 22 :width=>10, :fixed=>10, 23 :validate=>proc{|c| block_input}, 24 :decrement=>proc{spin_month -1}, 25 :increment=>proc{spin_month 1}) 26 @path = @spinner 27 @spinner.insert(0, Months[0]) 28 end 29end 30 31Spinner_demo.new.pack(:padx=>10, :pady=>10) 32 33Tk.mainloop 34