displays a photo : TkLabel « Tk « Ruby






displays a photo




#!/usr/bin/env ruby

require 'tk'
require "tkextlib/tkimg/jpeg"
require "open-uri"

photo = open("http://www.java2s.com/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

 








Related examples in the same category

1.Add a label to window
2.manipulates the font, the size of the label, and colors.