I know this is a Perl website and all, and I'm working strictly in Tcl/Tk, but whenever I dig around the Internet for Tcl/Tk guidance with my current project, for some reason I almost always find the answers here. Unfortunately, it's now come to a halt over what seems like a really simple/stupid problem so I decided I'd see if someone can help. Again, sorry it's not Perl I've already found several very similar threads here, and you seem like a very helpful bunch.

Basically, I have a simple popup window with a bunch of text entry boxes. For one of those boxes, called "manufacturer", I want to have a button that summons a popup menu so the user can select from several common manufacturers instead of having to type it in every time. The text entry box is still there, however, so that they can type in a manufacturer that's not contained in the list. The list of manufacturers is contained in a .txt document so that it's super easy to add and remove manufacturers at any time.

It seems like it should be really simple... the menu pops up the way I want, shows all of the manufacturers taken from the txt file, and fills in the entry box when you select something. However, it only fills in the entry box with the last entry in the list (Victrola). I've tried all kinds of variations and weird menu-related commands to get this thing to work, but it seems like that even though the "add command" part of setting up the menu gets the labels right, they all run the same command (the menu index is set to whatever Victrola is, rather than being different for every entry).

I would greatly appreciate any help that someone can offer! Here's the code:

### get the list of manufacturers from the .txt file set manufacturers {} set fid [open manufacturers.txt] while {[gets $fid line] != -1} { lappend manufacturers $line ) close $fid ### set up the menu frame .disc menu .disc.manu_menu -tearoff 0 foreach man $manufacturers { .disc.manu_menu add command -label "$man" -command {set disc_manufa +cturer $man} } pack [label .disc.manu_label -text "Manufacturer" -relief raised] -sid +e left bind .disc.manu_label <1> {tk_popup .disc.manu_menu %X %Y} ### here's the actual factual entry box entry .disc.manu_entry -width 30 -textvariable disc_manufacturer pack .disc.manu_entry -side left

The .txt file is just a simple list:

Capitol Columbia Edison RCA Victor Victrola

In reply to creating a Tk popup menu from a file by kurtasbestos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.