Ruby 完整布局管理示例

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

require "tk"

$top  = { 'side' => 'top', 'padx'=>5, 'pady'=>5 }
$left = { 'side' => 'left', 'padx'=>5, 'pady'=>5 }
$bottom = { 'side' => 'bottom', 'padx'=>5, 'pady'=>5 }

$temp = 74   # Starting temperature...

root = TkRoot.new { title "Thermostat" }

top = TkFrame.new(root) { background "#606060" }
bottom = TkFrame.new(root)

$tlab = TkLabel.new(top) do
  text $temp.to_s
  font "{Arial} 54 {bold}"
  foreground "green"
  background "#606060"
  pack $left
end

TkLabel.new(top) do         # the "degree" symbol
  text "o"
  font "{Arial} 14 {bold}"
  foreground "green"
  background "#606060"
  # Add anchor-north to the hash (make a superscript)
  pack $left.update({ 'anchor' => 'n' })
end

TkButton.new(bottom) do
  text " Up "
  command proc { $tlab.configure("text"=>($temp+=1).to_s) }
  pack $left
end

TkButton.new(bottom) do
  text "Down"
  command proc { $tlab.configure("text"=>($temp-=1).to_s) }
  pack $left
end

top.pack $top
bottom.pack $bottom

Tk.mainloop