Ruby/Tk/TkLabel

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Add a label to window

#!/usr/bin/env ruby
require "tk"
hello = TkRoot.new
TkLabel.new( hello ) do
    text "\n  Hello, Matz!  \n"
    pack
end
Tk.mainloop



displays a photo

#!/usr/bin/env ruby
require "tk"
require "tkextlib/tkimg/jpeg"
require "open-uri"
photo = open("http://www.crossplatform.ru/style/logo.png", "rb") {|io| io.read}
TkRoot.new {title "S" }
TkLabel.new {
  image TkPhotoImage.new( :data => Tk::BinaryString( photo ) )
  width 300
  pack
}
TkLabel.new {
  font TkFont.new( "verdana 24 bold" )
  text "Sunrise at sunset!"
  pack
}
TkButton.new {
  text "Quit"
  command "exit"
  pack
}
Tk.mainloop



manipulates the font, the size of the label, and colors.

It also provides a Quit button.
#!/usr/bin/env ruby
require "tk"
TkRoot.new {title "Ruby is fun!" }
TkLabel.new {
  font TkFont.new( "mistral 42" )
  text "Ruby is fun, in case you didn"t notice!"
  width 30
  height 3
  fg "blue"
  pack
}
TkButton.new {
  text "Quit"
  command "exit"
  pack
}
Tk.mainloop