# Change Gtk widget background/font/border color

**URL:** <https://discourse.julialang.org/t/change-gtk-widget-background-font-border-color/5552>\
**Category:** Visualization\
**Tags:** guis\
**Created:** [August 25, 2017, 1:52am UTC](https://discourse.julialang.org/t/change-gtk-widget-background-font-border-color/5552 "2017-08-25T01:52:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Loic\_Chappaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/loic_chappaz/32/1121_2.png) [@Loic\_Chappaz](https://discourse.julialang.org/u/Loic_Chappaz)\
**Post date:** [August 25, 2017, 1:52am UTC](https://discourse.julialang.org/t/change-gtk-widget-background-font-border-color/5552/1 "2017-08-25T01:52:15Z")

</div>

Hi!

We are building a GUI with Gtk.jl and we are using Notebook widgets to organize pages, and we have a couple nested Notebooks in there. To help track which tab/page is active, I would like to color the background of the notebook pages with different colors, or at least the border, or at the very least the font of the label of the page.

I’ve had some very limited success, drawing inspiration from [this](https://discourse.julialang.org/t/changing-gtk-widget-border-background-colors/5126) with things like:

```julia
using Gtk, Gtk.ShortNames

win = Window("Test")
lbl = Label("Some text")
a = GtkFrame("test")
push!(win, a)
push!(a, lbl)
sc = Gtk.GAccessor.style_context(lbl) 
pr = CssProviderLeaf(data="GtkLabel {color:red}")  
push!(sc, StyleProvider(pr), 600)
showall(win)

```

that will color the text of the label `lbl` in red. But, changing to:

```julia
using Gtk, Gtk.ShortNames

win = Window("Test")
lbl = Label("Some text")
a = GtkFrame("test")
push!(win, a)
push!(a, lbl) 
sc1 = Gtk.GAccessor.style_context(a)  
pr1 = CssProviderLeaf(data="frame {color:green;}")
push!(sc1, StyleProvider(pr1), 600) 
showall(win)

```

now colors both the label of the tab of the notebook and the label in green. I’m obviously missing something. Adding:

```julia
using Gtk, Gtk.ShortNames

win = Window("Test")
lbl = Label("Some text")
a = GtkFrame("test")
push!(win, a)
push!(a, lbl)
sc = Gtk.GAccessor.style_context(lbl)
sc1 = Gtk.GAccessor.style_context(a) 
pr = CssProviderLeaf(data="label {color:red;}")
pr1 = CssProviderLeaf(data="frame {color:green;}")
push!(sc1, StyleProvider(pr1), 600)
push!(sc, StyleProvider(pr), 600)
showall(win)

```

does not help…  
Any insight?  
Finally, I still would rather color the background and not just the font…As far as I understand, it may not be possible for some widget types, which apparently can be remedied by adding them to a GtkEventBox, at least in Python, but I didn’t find an equivalent in Gtk.jl. I might be missing something here, too…

Anyways, thanks for any insight on these questions you guys might have!  
Cheers,  
Loic

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [August 25, 2017, 6:11am UTC](https://discourse.julialang.org/t/change-gtk-widget-background-font-border-color/5552/2 "2017-08-25T06:11:32Z")

</div>

Somewhere in the Gtk documentation (“drawing model”) there is a description, that some widgets don’t have an own window (rectangle managed by the display system) but draw on their parent. Notebook might be such a case. I remember that i didn’t find EventBox either, maybe you put an issue on Gtk.jl. For some special requests on Gtk drawing (i wanted a different frame in frame) it’s only possible by replacing the draw method by an own function - something easy in pygtk but i haven’t done in julia (but it should be straight forward).

---

<div class="post-metadata">

**Author:** ![Loic\_Chappaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/loic_chappaz/32/1121_2.png) [@Loic\_Chappaz](https://discourse.julialang.org/u/Loic_Chappaz)\
**Post date:** [August 25, 2017, 6:46am UTC](https://discourse.julialang.org/t/change-gtk-widget-background-font-border-color/5552/3 "2017-08-25T06:46:27Z")

</div>

That’s what I gathered.  
Oh I see - I may dig up the draw function for the Notebook widget and see if I can tweak it. I lack some knowledge to do it originally…  
I also opened an [issue on Gtk.jl](https://github.com/JuliaGraphics/Gtk.jl/issues/323) and will update here if something comes out of it.

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [August 25, 2017, 7:25am UTC](https://discourse.julialang.org/t/change-gtk-widget-background-font-border-color/5552/4 "2017-08-25T07:25:17Z")

</div>

[http://www.pygtk.org/articles/cairo-pygtk-widgets/cairo-pygtk-widgets.htm](http://www.pygtk.org/articles/cairo-pygtk-widgets/cairo-pygtk-widgets.htm)

---

<div class="post-metadata">

**Author:** ![Loic\_Chappaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/loic_chappaz/32/1121_2.png) [@Loic\_Chappaz](https://discourse.julialang.org/u/Loic_Chappaz)\
**Post date:** [August 25, 2017, 2:47pm UTC](https://discourse.julialang.org/t/change-gtk-widget-background-font-border-color/5552/5 "2017-08-25T14:47:01Z")

</div>

Oh nice. Thanks for sharing.
