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
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)
Pascal T. 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. 
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!
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.