我正在制作一个简单的图像程序。我安装了chunky_png gem来处理png图像,但我不知道如何在窗口中绘图:
require 'chunky_png'
require 'tk'
town = ChunkyPNG::Image.from_file("town.png")
root = TkRoot.new
Tk.mainloop
在根窗口中绘制图像需要做什么?
答案 0 :(得分: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