Ruby窗口程序

require 'tk'
tkroot=TkRoot.new {
  title 'hellw word'
  geometry '300x200'
}
lb = TkLabel.new(tkroot) do  
  text 'hello'
  font 'arial 20 bold'
  pack :padx=>2,:pady=>2,:side=>'top'#使用pack把组件组装在界面中  
end
lb.bind("Enter"){
  lb.text='点击了'
 
}
Thread.start do  
  while true
    lb.text=Time.new.strftime("%Y-%m-%d %H:%M:%S")
    sleep(1)   
  end
  end

TkButton.new(tkroot){
  text '关闭'
  command {exit}
  pack :side=>'left',:padx=>10,:pady=>10
}

tkroot.mainloop
原文地址:https://www.cnblogs.com/smailxiaobai/p/4221219.html