# Should this this script error ? (Gtk::button and set\_image)

**URL:** <https://www.ruby-forum.com/t/should-this-this-script-error-gtk-button-and-set-image/75184>\
**Category:** Ruby-Gnome 2\
**Created:** [November 8, 2006, 2:11am UTC](https://www.ruby-forum.com/t/should-this-this-script-error-gtk-button-and-set-image/75184 "2006-11-08T02:11:10Z")\
**Posts on this page:** 2\
**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 8, 2006, 2:11am UTC](https://www.ruby-forum.com/t/should-this-this-script-error-gtk-button-and-set-image/75184/1 "2006-11-08T02:11:10Z")

</div>

Hi, I was trying to change the icons of a button when the  
mouse moves over the button, and when it moves out again.  
I was trying to use set\_image but I recieved a little error.  
Unsure whether this could be a bug, here is an  
example script (you probably need to use some  
own Images)

# SCRIPT START

require ‘gtk2’

# make button that holds first image

button = Gtk::Button.new()  
this\_image = Gtk::Image.new(‘/foobar.png’)

# assign 2 extra images

second\_image = Gtk::Image.new(‘/foobar1.jpg’)  
third\_image = Gtk::Image.new(‘/foobar2.jpg’)

button.set\_image this\_image  
button.set\_image second\_image  
button.set\_image third\_image  
button.set\_image this\_image  
button.set\_image second\_image

# add the things up

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

# SCRIPT END

The error I recieve is:

image\_test.rb  
(eval):5:in `set_property': destroyed GLib::Object (TypeError) from (eval):5:in `set\_image’  
from image\_test.rb:14

In another script where I try to use  
set\_image to get a new image, a similar error happens:  
in `set_property': destroyed GLib::Object from (eval):5:in `set\_image’

(On a sidenote, I was trying to change the icon of  
a button when the mouse hovers over the button, and when  
hovers out again, just like in Javascript. I am still not  
sure how to properly do this in ruby-gnome)

–

* * *

Get your free email from [http://www.linuxmail.org](http://www.linuxmail.org)

Powered by Outblaze

* * *

Using Tomcat but need to do more? Need to support web services,  
security?  
Get stuff done quickly with pre-integrated technology to make your job  
easier  
Download IBM WebSphere Application Server v.1.0.1 based on Apache  
Geronimo  
[http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642](http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642)

---

<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 9, 2006, 7:56pm UTC](https://www.ruby-forum.com/t/should-this-this-script-error-gtk-button-and-set-image/75184/2 "2006-11-09T19:56:00Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“[ruby-gnome2-devel-en] Should this this script error ? (Gtk::button  
and set\_image)” on Wed, 08 Nov 2006 02:02:37 +0100,  
“Roebe XXX” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi, I was trying to change the icons of a button when the  
> mouse moves over the button, and when it moves out again.  
> I was trying to use set\_image but I recieved a little error.  
> Unsure whether this could be a bug, here is an  
> example script (you probably need to use some  
> own Images)

I found a workaround. (Yes, really just a workaround)  
It’s that accessing button’s child before re-set\_image.

> button.set\_image this\_image  
> button.child  
> button.set\_image second\_image  
> button.child  
> button.set\_image third\_image  
> button.child  
> button.set\_image this\_image  
> button.child  
> button.set\_image second\_image

> (On a sidenote, I was trying to change the icon of  
> a button when the mouse hovers over the button, and when  
> hovers out again, just like in Javascript. I am still not  
> sure how to properly do this in ruby-gnome)

What about using Gtk::Stock instead of Gtk::Image? You can  
find Gtk::Stock sample Demo::AppWindow#register\_stock\_icons  
in gtk/sample/gtk-demo/appvindow.rb.

## Thanks,

kou

* * *

Using Tomcat but need to do more? Need to support web services,  
security?  
Get stuff done quickly with pre-integrated technology to make your job  
easier  
Download IBM WebSphere Application Server v.1.0.1 based on Apache  
Geronimo  
[http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642](http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642)
