# Background color

**URL:** <https://www.ruby-forum.com/t/background-color/238025>\
**Category:** Ruby-Gnome 2\
**Created:** [December 12, 2013, 11:29am UTC](https://www.ruby-forum.com/t/background-color/238025 "2013-12-12T11:29:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [December 12, 2013, 11:29am UTC](https://www.ruby-forum.com/t/background-color/238025/1 "2013-12-12T11:29:04Z")

</div>

Hi all,  
It’s been spoken about four times before, so I apologize for being  
dense. Does any one have an example of how to change a window’s  
background color in visual ruby?  
VisualRuby does a good job of being simple and straightforward, so it’s  
tough to know how to port the perl or python examples, or even the ruby  
examples.  
Thanks,  
Andru

---

<div class="post-metadata">

**Author:** ![quickshotjoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/cc9497/32.png) [@quickshotjoe](https://www.ruby-forum.com/u/quickshotjoe)\
**Post date:** [December 12, 2013, 8:06pm UTC](https://www.ruby-forum.com/t/background-color/238025/2 "2013-12-12T20:06:16Z")

</div>

Hi Andru:

Normally, I like setting attributes like background color using glade if  
I’m going to keep the same color at all times. However, I don’t see any  
setting in glade to set the background.

You can always do this:

def before\_show  
blue = Gdk::Color.parse("#CFFCFF")  
@builder[“window1”].modify\_bg(Gtk::STATE\_NORMAL, blue)  
end

Best,  
Eric

---

<div class="post-metadata">

**Author:** ![quickshotjoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/cc9497/32.png) [@quickshotjoe](https://www.ruby-forum.com/u/quickshotjoe)\
**Post date:** [December 15, 2013, 1:37am UTC](https://www.ruby-forum.com/t/background-color/238025/3 "2013-12-15T01:37:15Z")

</div>

Thanks a lot Eric! Works like a charm. I added it to show()  
def show()  
load\_glade( **FILE** )  
set\_glade\_all()  
blue = Gdk::Color.parse("#CFFCFF")  
@builder[“window1”].modify\_bg(Gtk::STATE\_NORMAL, blue)  
show\_window()  
end  
A

---

<div class="post-metadata">

**Author:** ![quickshotjoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/cc9497/32.png) [@quickshotjoe](https://www.ruby-forum.com/u/quickshotjoe)\
**Post date:** [December 15, 2013, 4:24am UTC](https://www.ruby-forum.com/t/background-color/238025/4 "2013-12-15T04:24:48Z")

</div>

No problem Andru.

Actually, since the last upgrade of vr, you can rewrite that method like  
so:

def before\_show()  
blue = Gdk::Color.parse("#CFFCFF")  
@builder[“window1”].modify\_bg(Gtk::STATE\_NORMAL, blue)  
end

There is a now a show() method in GladeGUI, and it calls before\_show()  
before showing the window on the screen.

The load\_glade() and set\_glade\_all() methods don’t need to be used in  
most programs since the last upgrade. The glade form is now  
automatically loaded and all the variables are automatically set.

In fact, if you don’t need to set the background color, you wouldn’t  
need any “show” type method at all. Most times you can just make the  
control names the same as your variable names, and do this:

MyClass.new.show

Understand? I’m sorry I haven’t documented it yet, but you can  
re-install the examples, and they demo the new format.

Thanks,  
Eric

---

<div class="post-metadata">

**Author:** ![quickshotjoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/cc9497/32.png) [@quickshotjoe](https://www.ruby-forum.com/u/quickshotjoe)\
**Post date:** [December 15, 2013, 10:42pm UTC](https://www.ruby-forum.com/t/background-color/238025/5 "2013-12-15T22:42:37Z")

</div>

Thanks so much. I wish I could take credit for everything, but like you  
said, I’m jut putting together great things that others have created.  
Without Ruby language then ruby-gnome then visualruby with the  
assistance of the glade people none of it is possible.

Not to mention that I’ve been totally dependent on the geniuses on this  
site for advise. 🙂

I’d love to see what you make with it.

Eric

---

<div class="post-metadata">

**Author:** ![quickshotjoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/cc9497/32.png) [@quickshotjoe](https://www.ruby-forum.com/u/quickshotjoe)\
**Post date:** [December 16, 2013, 2:33am UTC](https://www.ruby-forum.com/t/background-color/238025/6 "2013-12-16T02:33:18Z")

</div>

I used to work at a community television station and built their playout  
system (kind of as an after work hobby). Now I am volunteering to finish  
it off (so someone else can look after it hopefully!).  
I’m using a bunch of pieces like VLC and powerpoint to run the station  
in a novel way.  
I have an image of an early mockup.  
It’s kind of like a very long chess game.

---

<div class="post-metadata">

**Author:** ![quickshotjoe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/cc9497/32.png) [@quickshotjoe](https://www.ruby-forum.com/u/quickshotjoe)\
**Post date:** [December 15, 2013, 9:31am UTC](https://www.ruby-forum.com/t/background-color/238025/7 "2013-12-15T09:31:53Z")

</div>

I think I do understand.  
Eric, you have created a thing of magic. I still can’t believe that I  
can use Ruby to create a GUI interface. I know that we are all standing  
on the shoulders of giants here, but you have created this last link  
that works so well for me.  
Thanks,  
Andru
