2012-05-31 55 views
1

我正在制作一个简单的图像程序。我安装了chunky_png宝石来处理PNG图像,但我不知道如何在窗口中绘制:如何使用Ruby来显示图像?

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

什么我需要做的,画在根窗口中的图像?

回答

0

看一看在tk文件http://www.tutorialspoint.com/ruby/ruby_tk_fonts_colors_images.htm

这里是如何显示图像的例子:

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