Forum: Ruby-Gnome 2 Setting the Image of a Button

Posted by Ian D. (soilworker)
on 2010-02-07 23:37
Hello everyone,

I'm pretty new to both Ruby and Ruby-Gnome2. I am trying to create a GUI
for TicTacToe and I'm running into some problems. I would like to be
able to set the image of a button and then have it change its image when
clicked. So far I have been unsuccessful at getting an image to even
show up on a button. I am aware that it is possible to do this with the
EventBox but I would really like to see it work with a Button. Here is
the code that I am trying to use:

require 'gtk2'

def change_img(widget)
    image2 = Gtk::Image.new("images/face-cool.png")
    widget.image = image2
end

image1 = Gtk::Image.new("images/face-sad.png")

button0 = Gtk::Button.new("0")
button0.image = image1

#Attach signals
button0.signal_connect( "clicked" ) do |w|
    change_img(w)
end

box1 = Gtk::VBox.new(false, 0)
box1.pack_start(button0, false, false, 0)

window = Gtk::Window.new("Button Images")
window.set_default_size(200,200)

window.signal_connect("delete_event") {
  false
}

window.signal_connect("destroy") {
  puts "destroy event occured"
  Gtk.main_quit
}

window.add(box1)
window.show_all
Gtk.main
Posted by Pascal Terjan (Guest)
on 2010-02-07 23:46
(Received via mailing list)
Le dimanche 07 février 2010 à 23:37 +0100, Soil Soil a écrit :
> Hello everyone,
> 
> I'm pretty new to both Ruby and Ruby-Gnome2. I am trying to create a GUI
> for TicTacToe and I'm running into some problems. I would like to be
> able to set the image of a button and then have it change its image when
> clicked. So far I have been unsuccessful at getting an image to even
> show up on a button. 

You code set the image fine here (and changes it when I click on the
button)
Posted by Ian D. (soilworker)
on 2010-02-08 02:07
Pascal Terjan wrote:
> Le dimanche 07 f�vrier 2010 � 23:37 +0100, Soil Soil a �crit :
>> Hello everyone,
>> 
>> I'm pretty new to both Ruby and Ruby-Gnome2. I am trying to create a GUI
>> for TicTacToe and I'm running into some problems. I would like to be
>> able to set the image of a button and then have it change its image when
>> clicked. So far I have been unsuccessful at getting an image to even
>> show up on a button. 
> 
> You code set the image fine here (and changes it when I click on the
> button)

Hmmm thats wierd. I tried the code on my laptop, which is running Ubuntu 
9.04, and it runs just fine but on my desktop with Ubuntu 9.10 it 
doesn't work. :(
Posted by Ian D. (soilworker)
on 2010-02-08 04:47
If anyone is running Ubuntu 9.10, could they pelase run the code and see 
if it works? I would like to know whether or not it is my machine or 
just the OS that is causing the problem. Thanks!
Posted by Robert Mrasek (derobo)
on 2010-02-08 07:55
Ian D. wrote:
> If anyone is running Ubuntu 9.10, could they pelase run the code and see 
> if it works? I would like to know whether or not it is my machine or 
> just the OS that is causing the problem. Thanks!

I using Ubuntu 9.10 too and i don't see any image (i changed the path of
course). I also don't see image on buttons when I'm using stocks (the 
text and
mnemonic works). I'm using ruby 1.8.7 (2009-06-12 patchlevel 174) 
[x86_64-linux] and ruby-gnome/ruby-gnome-dev 0.19-2ubuntu4.

I will try building form source later, how that will help.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.