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

radiobutton / checkbutton text in multiple colors

12 views
Skip to first unread message

sch...@imb-jena.de

unread,
Jul 31, 2005, 4:55:04 AM7/31/05
to
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

unread,
Jul 31, 2005, 7:03:44 AM7/31/05
to
sch...@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 as...@triumf.ca

Peter Schellenberg

unread,
Jul 31, 2005, 11:02:33 AM7/31/05
to
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

unread,
Jul 31, 2005, 3:05:53 PM7/31/05
to
"Peter Schellenberg" <sch...@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 as...@triumf.ca

0 new messages