For Programmers: Free Programming Magazines  


Home > Archive > Tcl > July 2005 > radiobutton / checkbutton text in multiple colors









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 radiobutton / checkbutton text in multiple colors
schelli@imb-jena.de

2005-07-31, 4:01 am

Hi ,

I would like to create text in different colors within the text field
of a radiobutton (or analogously a button, checkbutton or hypertext) :


radiobutton $w.left.b$i -text "Text in 1st color, 2nd color, 3rd color"
-variable i1 -relief flat -value $i

It would be convenient to first define the text as a variable:

set mytext "Text in 1st color, 2nd color, 3rd color"
radiobutton $w.left.b$i -text "$mytext" -variable i1 -relief flat
-value $i

How can I do this in TCL/Tk ? I am aware of the tag syntax:
$w.text tag configure color2 -foreground red
....
$w.text insert end "Text in color 2" color2

however, I am not able to apply this in a text field of a button or to
the definition of a variable.

Thanks for help in advance Peter

Donald Arseneau

2005-07-31, 9:00 am

schelli@imb-jena.de writes:

> I would like to create text in different colors within the text field
> of a radiobutton (or analogously a button, checkbutton or hypertext) :



text $w -relief raised -bd 2

> $w tag configure color2 -foreground red
> $w insert end "Text in color 2" color2


bind $w <1> { $w configure -relief sunken; update;
action
after 30 $w configure -relief raised}

or something like that.

--
Donald Arseneau asnd@triumf.ca
Peter Schellenberg

2005-07-31, 5:18 pm

Dear Donald,

thanks for the answer. However I wonder if it is the answer to my
question, especially since I wanted to have different colors within one
text for the same button like:

radiobutton $w.left.b$i -text "Text in 1st color, 2nd color, 3rd color"
-variable i1 -relief flat -value $i

I am sorry that I am not more familiar with TCL/Tk but I only need it
in connection with a program that uses it as an embedded scripting
language

Kind regards Peter

Donald Arseneau

2005-07-31, 10:03 pm

"Peter Schellenberg" <schelli@imb-jena.de> writes:

> thanks for the answer. However I wonder if it is the answer to my
> question, especially since I wanted to have different colors within one
> text for the same button like:


set w .tb
text $w -relief raised -bd 2 \
-width 25 -height 1 \
-cursor {}

$w tag configure color2 -foreground red
$w insert end " Fake Button with "
$w insert end "text in color " color2

$w configure -state disabled

bind $w <1> { $w configure -relief sunken
set press_mess "Button pressed [incr press_count] times"
}
bind $w <ButtonRelease-1> {
after 30 $w configure -relief raised
}

label .mess -textvar press_mess
set press_count 0
set press_mess "Button pressed 0 times"

pack .tb .mess


It is even easier for radio buttons and check buttons beca


> radiobutton $w.left.b$i -text "Text in 1st color, 2nd color, 3rd color"
> -variable i1 -relief flat -value $i
>
> I am sorry that I am not more familiar with TCL/Tk but I only need it
> in connection with a program that uses it as an embedded scripting
> language
>
> Kind regards Peter
>


--
Donald Arseneau asnd@triumf.ca
Sponsored Links







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

Copyright 2008 codecomments.com