- 309 名前:デフォルトの名無しさん mailto:sage [2009/01/05(月) 10:19:00 ]
- require 'tk'
class Drill100 PACKOPT = {:side=>:left,:fill=>:both,:expand=>true} PACKOPTF = {:side=>:top,:fill=>:both,:expand=>true} CELLOPT = {:width=>3} def initialize(root) @root = root @root.title = '100マス計算' @size,@min,@max = ( $test ? [2,0,9] : [10,11,99] ) @column,@row,@cells = [],[],[] f = TkFrame.new(@root).pack(PACKOPTF) @reset = TkButton.new(f,:text=>'切替',:command=>proc{init}).pack(:side=>:left) @start = TkButton.new(f,:text=>'開始',:command=>proc{start}).pack(:side=>:left) f = TkFrame.new(@root).pack(PACKOPTF) @op = TkLabel.new(f,CELLOPT).pack(PACKOPT) @size.times {|i| @column << TkLabel.new(f,CELLOPT).pack(PACKOPT) } @size.times do |i| f = TkFrame.new(@root).pack(PACKOPTF) @row << TkLabel.new(f,CELLOPT).pack(PACKOPT) @cells << [] @size.times {|j| @cells[i] << TkEntry.new(f,CELLOPT).pack(PACKOPT) } end end def init @reset.state = :normal @start.configure(:text=>'開始',:command=>proc{start}) @op.text = {'+'=>'-','-'=>'*','*'=>'+'}[@op.text] || '+' [@column,@row].each {|labels| labels.each {|l| l.text = random(@min,@max).to_s }} @cells.each {|line| line.each {|cell| cell.state = :disabled }} end # つづく
|

|