免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2353 | 回复: 1
打印 上一主题 下一主题

Ruby 完整布局管理示例 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-01-16 18:32 |只看该作者 |倒序浏览
  1. require "tk"

  2. $top  = { 'side' => 'top', 'padx'=>5, 'pady'=>5 }
  3. $left = { 'side' => 'left', 'padx'=>5, 'pady'=>5 }
  4. $bottom = { 'side' => 'bottom', 'padx'=>5, 'pady'=>5 }

  5. $temp = 74   # Starting temperature...

  6. root = TkRoot.new { title "Thermostat" }

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

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

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

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

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

  34. top.pack $top
  35. bottom.pack $bottom

  36. Tk.mainloop
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-01-16 23:16 |只看该作者
是Tk的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP