Chinaunix

标题: Ruby 完整布局管理示例 [打印本页]

作者: boy11-2    时间: 2011-01-16 18:32
标题: Ruby 完整布局管理示例
  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
复制代码

作者: 2gua    时间: 2011-01-16 23:16
是Tk的。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2