Ruby 完整布局管理示例

2015-04-04 0 237
Ruby 完整布局管理示例
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

遇见资源网 ruby Ruby 完整布局管理示例 http://www.ox520.com/16327.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务