Chinaunix
标题:
Ruby 完整布局管理示例
[打印本页]
作者:
boy11-2
时间:
2011-01-16 18:32
标题:
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
复制代码
作者:
2gua
时间:
2011-01-16 23:16
是Tk的。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2