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

Border around widgets?

63 views
Skip to first unread message

catt...@ig.com.br

unread,
Aug 20, 2012, 2:38:58 PM8/20/12
to
Dear fellow Tclers,

Is there any standard way to dinamically draw a coloured border around any given widget (a label, a ttk::button, a frame, etc) which is already visible in the screen?

I thought about picking the widget out of its parent, putting in its place a frame with its -background option configured to the desired color, then put the widget in this frame with padding options. But maybe there is another method which is more efficient/fast and has no effect on the surrounding widgets (like enlarging the grid, etc)...

Thanks!

Fabricio Rocha
Brasilia, Brasil

George Petasis

unread,
Aug 20, 2012, 3:05:46 PM8/20/12
to
Do you need each widget to have a different coloured border?

George

fabricior...@gmail.com

unread,
Aug 20, 2012, 10:13:59 PM8/20/12
to
Hi, George! No, not exactly a different border color for each widget. I just want to have a highlight effect on a widget by placing a border around it.

Thanks for your attention!

Fabricio Rocha
Brasilia, Brasil

Rich

unread,
Aug 20, 2012, 10:24:21 PM8/20/12
to
On Monday, August 20, 2012 2:38:58 PM UTC-4, (unknown) wrote:
> Is there any standard way to dinamically draw a coloured border around any given widget (a label, a ttk::button, a frame, etc) which is already visible in the screen?

This is for Tk widgets:

man options:
...
[-highlightbackground highlightBackground] Specifies
the color to display in the traversal highlight
region when the widget does not have the input
focus.

wish
% button .b -text "I AM A BUTTON"
.b
% pack .b
% .b configure -highlightbackground blue

And the button suddenly had a blue border. At least on Linux that is.

fabricior...@gmail.com

unread,
Aug 21, 2012, 2:12:12 AM8/21/12
to
This is the effect, Rich, thank you! I had read about the -highlight* options but still had not got a chance to test them.

Anyway, it is really a pity and a serious limitation for my purposes that it does not work for Ttk widgets. I still have to find an "universal" method which would work for both.

Maybe is there a way to, kind of, add the -highlightbackground property to Ttk widgets by using ttk::style or the options database? Or packing/griding a colored frame in the same position of the widget and push it down with [lower]? I experimented a little bit, but couldn't really get the desired result...

Thanks once again!

Fabricio Rocha
Brasilia, Brasil

Schelte Bron

unread,
Aug 21, 2012, 7:44:42 AM8/21/12
to
fabricior...@gmail.com wrote:
> Anyway, it is really a pity and a serious limitation for my
> purposes that it does not work for Ttk widgets. I still have to
> find an "universal" method which would work for both.
>
> Maybe is there a way to, kind of, add the -highlightbackground
> property to Ttk widgets by using ttk::style or the options
> database? Or packing/griding a colored frame in the same position
> of the widget and push it down with [lower]? I experimented a
> little bit, but couldn't really get the desired result...
>
There's a third geometry manager that probably works best for this
job:

proc highlight {w {bg red} {bd 2}} {
set h [frame $w-highlight -background $bg]
place $h -in $w -x -$bd -y -$bd \
-relwidth 1 -width [expr {2 * $bd}] \
-relheight 1 -height [expr {2 * $bd}]
# raise $w
lower $h $w
return $h
}

Uncommenting the raise command may give you better visual results
when widgets are close together, but it also changes the order for
keyboard traversal. Pick whichever option is most important for your
application.


Schelte.

fabricior...@gmail.com

unread,
Aug 21, 2012, 9:52:39 AM8/21/12
to
Whoa, Schelte, this worked fine! Finally I see a real utility for the "place" manager! :) I must admit I have overlooked it a lot...

Thank you very much!

Fabricio Rocha
Brasilia, Brasil
0 new messages