# Gtk::DrawingArea and Icons

**URL:** <https://www.ruby-forum.com/t/gtk-drawingarea-and-icons/153040>\
**Category:** Ruby-Gnome 2\
**Created:** [November 11, 2008, 12:54pm UTC](https://www.ruby-forum.com/t/gtk-drawingarea-and-icons/153040 "2008-11-11T12:54:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [November 11, 2008, 12:54pm UTC](https://www.ruby-forum.com/t/gtk-drawingarea-and-icons/153040/1 "2008-11-11T12:54:27Z")

</div>

Hi,

is it possible to put up images/icons within a Gtk::DrawingArea?

I.e. if i have the image of a little cat, can this be displayed on it?

Right now I only saw examples with custom elements, things like

cairo\_context = widget.window.create\_cairo\_context  
cairo\_context.scale(\*widget.window.size)

Thanks

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [November 11, 2008, 2:43pm UTC](https://www.ruby-forum.com/t/gtk-drawingarea-and-icons/153040/2 "2008-11-11T14:43:28Z")

</div>

On Tue, Nov 11, 2008 at 12:54 PM, Marc H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> is it possible to put up images/icons within a Gtk::DrawingArea?
> 
> I.e. if i have the image of a little cat, can this be displayed on it?

Generally, it’s easy to work with pixbufs.

require ‘gtk2’

class MainView \< Gtk::DrawingArea

```
def initialize
    super()
    signal_connect('expose-event') { draw }
    signal_connect('configure-event') { update_shown }
end

def update_shown
    w, h = window.size
    puts "my size: #{w}x#{h}"
    #- normally you could create a pixbuf related to w,h (scaling

```

images, drawing…)  
@pixbuf = Gtk::Image.new(‘/tmp/foo.png’).pixbuf  
return true  
end

```
def draw
    window.draw_pixbuf(nil, @pixbuf, 0, 0, 10, 10, -1, -1,

```

Gdk::RGB::DITHER\_NONE, -1, -1)  
end  
end

Gtk.init

w = Gtk::Window.new  
w.add(MainView.new)  
w.show\_all

Gtk.main

–  
Guillaume C. - [Guillaume Cottenceau](http://zarb.org/~gc/)

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [November 11, 2008, 5:22pm UTC](https://www.ruby-forum.com/t/gtk-drawingarea-and-icons/153040/3 "2008-11-11T17:22:09Z")

</div>

Thanks a lot Guillaume.

Customized Interfaces, here I come! 🙂
