At Tue, 12 Dec 2000 12:31:51 +0900,
Nathaniel Talbott wrote:
> 
> Help! I can't seem to change the color of a gtk widget dynamically within
> Ruby. I have no trouble changing the color initially, by setting the proper
> Style property before the widget is shown, but nothing seems to happen if I
> change the style after the widget is shown.

require 'gtk'

window = Gtk::Window.new

# create two Style for two different color.
# you can't modify style's color in signal handlers

red = Gtk::Style.new
blue = Gtk::Style.new

# make red be red, blue be blue

red.set_bg(Gtk::STATE_NORMAL, 65535, 0, 0)
blue.set_bg(Gtk::STATE_NORMAL, 0, 0, 65535)

button = Gtk::Button.new 'Hello, World'

bool = false
button.signal_connect('clicked') do
  if bool
    window.set_style red
    bool = false
  else
    window.set_style blue
    bool = true
  end
  # don't forget to redraw so that the change show up
  window.queue_draw
end

window.signal_connect('delete-event') do
  Gtk.main_quit
end
window.border_width = 10
window.add button
button.show
window.show
Gtk.main
--
         yashi