kim taeyun
kim taeyun

Reputation: 1847

How do I use Ruby to display an image?

I am making a simple image program. I installed the chunky_png gem to handle png images, but I have no idea how to draw in the window:

require 'chunky_png'
require 'tk'
town = ChunkyPNG::Image.from_file("town.png")
root = TkRoot.new
Tk.mainloop

What do I need to do to draw an image in the root window?

Upvotes: 2

Views: 4778

Answers (1)

Green Su
Green Su

Reputation: 2348

Have a look at the tk document http://www.tutorialspoint.com/ruby/ruby_tk_fonts_colors_images.htm

Here is an example of how to display image:

require 'tk'

$resultsVar = TkVariable.new
root = TkRoot.new
root.title = "Window"

image = TkPhotoImage.new
image.file = "zara.gif"

label = TkLabel.new(root) 
label.image = image
label.place('height' => image.height, 
            'width' => image.width, 
            'x' => 10, 'y' => 10)
Tk.mainloop

Upvotes: 1

Related Questions