For Programmers: Free Programming Magazines  


Home > Archive > Tcl > February 2005 > button -compound right









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author button -compound right
Wolf Grossi

2005-02-23, 4:01 pm

Hi all,

creatig several same sized buttons with centered text, I want to have an
image on the right end of the buttons.
Is this possible?
Using the '-compond right' option places the image on the right side of
the button-text, but I want to have it on the right side of the button.

Any hints?
Thanks
Wolf
Jeff Hobbs

2005-02-23, 4:01 pm

Wolf Grossi wrote:
> creatig several same sized buttons with centered text, I want to have an
> image on the right end of the buttons.
> Is this possible?
> Using the '-compond right' option places the image on the right side of
> the button-text, but I want to have it on the right side of the button.


You cannot anchor the text/image elements separately, as they
are placed as a logical unit. You can adjust their anchoring
in the button space with -anchor.

--
Jeff Hobbs, The Tcl Guy
http://www.ActiveState.com/, a division of Sophos
Wolf Grossi

2005-02-23, 4:01 pm

Jeff Hobbs wrote:
> Wolf Grossi wrote:
>
>
>
> You cannot anchor the text/image elements separately, as they
> are placed as a logical unit. You can adjust their anchoring
> in the button space with -anchor.
>

Wow! that was fast :-))
Thanks a lot.
Wolf
Schelte Bron

2005-02-23, 8:59 pm

Wolf Grossi wrote:
> creatig several same sized buttons with centered text, I want to have an
> image on the right end of the buttons.
> Is this possible?
> Using the '-compond right' option places the image on the right side of
> the button-text, but I want to have it on the right side of the button.
>

I've been getting acceptable results with the code below. It basically calls
a procedure whenever the button changes size. The procedure calculates the
space available for the text and adds spaces around the text to fill this
space as much as possible. You have to be careful not to add too many
spaces or you will end up with ever expanding buttons. On your buttons you
should set the -anchor option to the side where you put the image.

proc CompoundButtonAlign {path} {
foreach opt {padx bd highlightthickness font image text} {
set $opt [$path cget -$opt]
}
set w [expr {[winfo width $path] -
(($highlightthickness + $padx + $bd) << 1)}]
if {[string length $image]} {
set img [image width $image]
} else {
set img 0
}
set sp [font measure $font " "]
set txt ""
foreach n [split $text \n] {
set n [string trim $n]
set m [font measure $font $n]
set c [expr {($w - $img - $m) / $sp - 2 >> 1}]
set spc [string repeat " " $c]
lappend txt $spc$n$spc
}
$path configure -text [join $txt \n]
}

bind CompoundButton <Configure> {CompoundButtonAlign %W}

# Perform the following command for each compound button
bindtags $button [linsert [bindtags $path] 2 CompoundButton]


Schelte.
--
set Reply-To [string map {nospam schelte} $header(From)]
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com