For Programmers: Free Programming Magazines  


Home > Archive > Tcl > November 2007 > formatting text in combobox









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 formatting text in combobox
raaki

2007-11-21, 8:13 am

Hi members,
I have a combobox that I want different text displayed after user
selects an item from the combo(i am using Mr.Byrans Tcl combox 2.3).

How can I change the text filled in the combobox when user selects an
item?

details:lets say i have list with versions 2.3,2.4,2.5

when selected 2.3 it must be replaced with apps/version2.3/docs/txt.
2.3

any suggestions or commands.
billposer@alum.mit.edu

2007-11-21, 10:15 pm

On Nov 21, 2:41 am, raaki <hemanth...@gmail.com> wrote:
> Hi members,
> I have a combobox that I want different text displayed after user
> selects an item from the combo(i am using Mr.Byrans Tcl combox 2.3).
>
> How can I change the text filled in the combobox when user selects an
> item?
>
> details:lets say i have list with versions 2.3,2.4,2.5
>
> when selected 2.3 it must be replaced with apps/version2.3/docs/txt.
> 2.3
>
> any suggestions or commands.


The combobox command has a -command option that lets you specify a
command to be executed whenever an item is selected. You could use
that to specify a procedure that replaces the text of the selected
entry.
Bryan Oakley

2007-11-21, 10:15 pm

raaki wrote:
> Hi members,
> I have a combobox that I want different text displayed after user
> selects an item from the combo(i am using Mr.Byrans Tcl combox 2.3).
>
> How can I change the text filled in the combobox when user selects an
> item?
>
> details:lets say i have list with versions 2.3,2.4,2.5
>
> when selected 2.3 it must be replaced with apps/version2.3/docs/txt.
> 2.3
>
> any suggestions or commands.


Use the -command option to specify a command that changes the value
whenever the user selects something.

combobox::combobox .cb \
-width 32 \
-command updateCombo \
-listvar choices
pack .cb -side top -fill x
set choices {2.3 2.4 2.5}

proc updateCombo {w value} {
$w configure -commandstate disabled
set version $value
set value "apps/version$version/docs/txt.$version"
$w configure -value $value
$w configure -commandstate normal
}




--
Bryan Oakley
http://www.tclscripting.com
coolmaster79@googlemail.com

2007-11-22, 4:34 am


> Use the -command option to specify a command that changes the value
> whenever the user selects something.
>
> combobox::combobox .cb \
> -width 32 \
> -command updateCombo \
> -listvar choices
> pack .cb -side top -fill x
> set choices {2.3 2.4 2.5}
>
> proc updateCombo {w value} {
> $w configure -commandstate disabled
> set version $value
> set value "apps/version$version/docs/txt.$version"
> $w configure -value $value
> $w configure -commandstate normal

hi all

i have a question. does this -command option support for a list of
elements.previously i had similar kind of problem.

there is a list of combobox elements out of which ,only few elements
text need to be replaced according to the option selected from
pulldown menu,rest of the elemnts combobox procedure must be same.but
when i used command option it is replacing all the elements in the
list with perticular string.

couldnt find a sol,i did by removing elements from the list and
predeclared by using "bind" option for each case.

can any one help with an example how to solve this kind of case

thanks
Bryan Oakley

2007-11-22, 8:12 am

master79@googlemail.com wrote:
>
> hi all
>
> i have a question. does this -command option support for a list of
> elements.


No.

The command doesn't support lists. It is called when something is
selected from the list, and you can only pick one thing.

What you do in the proc that is called is entirely up to you.

What I would suggest is simply make a translation table. If there's no
translation for an item, do nothing. Here's an untested solution:

proc updateCombo {w value} {
global translation
if {[info exists translation($value)]} {
$w configure -commandstate disabled
$w configure -value $translation($value)
$w configure -commandstate normal
}
}

set translation(2.1) "apps/version2.1/docs/txt.2.1"
set translation(2.2) "apps/version2.2/docs/txt.2.2"
....
Sponsored Links







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

Copyright 2008 codecomments.com