Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve combo box values

Status
Not open for further replies.

anirban2k2001

Programmer
Aug 25, 2003
27
IN
Hi all!

My combo box fetches values from a backend database.But when I select any value, only the last value in the list is displayed.

Kindly help.

I am giving below the code for reference:

############################################################
# To use alchemy API do the following
package require picoapi
update idletasks

# The following gets executed, when the application is closed
wm protocol . WM_DELETE_WINDOW {
# You can do some wrap-up work here, before the application quits
exit
}

source combobox.tcl
package require combobox 2.3
catch {namespace import combobox::*}

# Following are the different kind of PicoPeta fonts
# set fnt7 "-picopeta-simputer-medium-r-normal--7-120-101-108-p-120-fontspecific-0"
# set fnt9 "-picopeta-simputer-medium-r-normal--9-120-101-108-p-120-fontspecific-0"
# set fnt11 "-picopeta-simputer-medium-r-normal--11-120-101-108-p-120-fontspecific-0"
# set fnt11b "-picopeta-simputer-bold-r-normal--11-120-101-108-p-120-fontspecific-0"
# set fnt14 "-picopeta-simputer-medium-r-normal--14-120-101-108-p-120-fontspecific-0"

# Set the title and the status here
# By default title and status fonts are fnt9
# Status message is always right justified by default
wm title . "Meter Details"
alchemy status_msg "Meter Details"

# Annotate icon is ON by default. Turn it OFF, because we don't need it here.
# Using the annotation is shown in example 006
alchemy annotate off

# Hard coded value for temporary purposes
set argc 2

if {$argc!=2} {

puts stderr "Database error"
exit 1

}

set fp [frame .fontpicker]
set msg [label .msg -borderwidth 2 -relief groove -width 30 -height 4]

pack $fp -side top -fill x
pack $msg -side top -fill both -expand y -pady 2

load /usr/lib/tclsqlite-2.8.15.so Sqlite
sqlite db1 /root/cesc_simputer.db

label $fp.famLabel -text "Select Consumer No:"
combobox $fp.famCombo \
-borderwidth 1 \
-textvariable abc \
-editable false \
-highlightthickness 1 \
-command


  • grid $fp.famLabel -row 0 -column 0 -sticky e
    grid $fp.famCombo -row 0 -column 1 -sticky ew
    grid columnconfigure $fp 1 -weight 1

    db1 eval {select con_no from mri} values {
    parray values
    $fp.famCombo list insert end $values(con_no)
    puts ""
    }

    # Buttons to change the keyboard layout
    # button .b1 -text "Submit" -command {alchemy source test.tcl}
    button .b1 -text "Submit" -command {puts $values(con_no)}
    place .b1 -x 40 -y 40 -width 90 -height 25

    button .b2 -text "Exit" -command exit
    place .b2 -x 140 -y 40 -width 90 -height 25

    ############################################################
 
I assume you're using the "ComboBox" widget from BWidgets. If so, you need, I think, to specify a "-values" option to provide a list of values. Also, I don't know what [red]$fp.famCombo list insert end $values(con_no)[/red] does. I don't see a "list" command in the ComboBox help documentation.

Granted, I have never used the ComboBox so I don't really know how it works.

Bob Rashkin
rrashkin@csc.com
 
Hi
I joined this forum today. I have created a combo box widget with the following code:

package require Iwidgets 4.0
# proc selectCmd {} {
# puts stdout [.cb2 getcurselection]
# }

iwidgets::combobox .cb1 -labeltext "Month:" -labelpos w \-selectioncommand {
puts selected: [.cb1 getcurselection]"
}
.cb1 insert list end Jan Feb Mar Apr May June Jul Aug Sept Oct Nov Dec
pack .cb1

I was getting the combo box but my problem is that i need to attach this combo box to a menubar which i have created. What changes do i have to make in the code..please let me know clearly..
regards
ramaka71
 
I would recommend using either iwidgets or bwidgets for your combobox. These are supported by ActiveState and are simple to use. To return the value with a bwidget combobox, you would say:

.combobox getvalue

That returns an index. To get the text of that index:

set text [lindex [.combobox cget -values] [.combobox getvalue]]

More documentation can be found here:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top