Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ttk widgets: changing the background colour?

2,080 views
Skip to first unread message

Georgios Petasis

unread,
Mar 24, 2010, 2:08:29 PM3/24/10
to
Hi all,

Does anybody knows how can I change the background colour of a ttk
widget? (In this case the shash of a pane, and the background of a
notebook).

I have this window:
http://www.ellogon.org/~petasis/tcl/TkRibbon/images/Ellogon-Ribbon-System-Logs.png

I want to change the background colour at the tab area (beneath Output,
Time Log & Error Log), but without loosing the native tabs.

I have a rough idea that I need to create a new "style" (is this
correct?) but I don't know how to start.
Is this feasible?

(The wiki seems too slow today, so I cannot search for the time being...)

George

Georgios Petasis

unread,
Mar 24, 2010, 2:57:48 PM3/24/10
to

I tried this:


package req Tk

ttk::style layout System.notebook {
Notebook.client -sticky nswe
}
ttk::style configure System.notebook -background red

ttk::notebook .x
for {set i 0} {$i < 10} {incr i} {
.x add [frame .x.f$i] -text $i
pack [text .x.f$i.t -height 4 -width 60]
}
pack .x -fill both -expand true

A complete failure: I only get half tabs :D

George

Georgios Petasis

unread,
Mar 24, 2010, 3:53:23 PM3/24/10
to
στις 24/3/2010 20:08, O/H Georgios Petasis έγραψε:

Ok, the following works:

ttk::style configure TNotebook -background red

But, this changes all notebooks. I tried to create a new layout:

ttk::style layout System.Notebook {
Notebook.client -sticky nswe
}

When I use it on a notebook, I get the correct colour, but the tabs do
not resize as supposed (and do with the default layout).
What is the layout I define missing?

George

Schelte Bron

unread,
Mar 24, 2010, 5:14:22 PM3/24/10
to
Georgios Petasis wrote:
> Ok, the following works:
>
> ttk::style configure TNotebook -background red
>
> But, this changes all notebooks. I tried to create a new layout:
>
> ttk::style layout System.Notebook {
> Notebook.client -sticky nswe
> }
>
> When I use it on a notebook, I get the correct colour, but the
> tabs do not resize as supposed (and do with the default layout).
> What is the layout I define missing?
>
It is a misconception to think there even is such a thing as a
background color for ttk::widgets. Some themes may use a gradient or
a pattern for the background. So at best your strategy will only
work with some themes and you should reconsider if this is really
what you want to do.

If you still decide you want to change the background color of the
notebook, you don't have to create a new layout. After all, you are
not changing the layout, just the color. So simply use:

ttk::style configure System.TNotebook -background red
ttk::notebook .nb -style System.TNotebook


Schelte.

George Petasis

unread,
Mar 24, 2010, 6:36:44 PM3/24/10
to

Dear Schelte,

Thanls, it works. I had no idea that I can configure a non-existing style...

George

MSEdit

unread,
Mar 25, 2010, 9:11:27 AM3/25/10
to

Have a look here for a good explication http://www.tkdocs.com/tutorial/styles.html

Its not complete yet but is an excellent intro

Martyn

0 new messages