Hi props,

I think what you're looking for is this:

use strict; use warnings; use Tk; # User-defined my @menubutton_items = ( 'supplier 1', 'supplier 2', 'supplier 3', 'supplier 3', ); # Main program my $chosen_item = ""; my $mw = new MainWindow; $mw->geometry("400x400+200+0"); my $frm_name = $mw-> Frame( -relief=>'groove', -borderwidth=>5, -background=>'black' )->pack(-side =>'top', -fill=>'x'); my $expensemb = $frm_name->Menubutton( -tearoff => 0, -text =>"Eksodo", )->pack(-side=>'left',-anchor=>'nw'); # Pack each item into the Menubutton foreach my $item (@menubutton_items) { $expensemb->command(-label => $item, -command => sub { addtext($it +em) }); } my $costlabel = $frm_name -> Label(-text=>"Timh", -background => 'red') -> pack(-side=>'left', -anchor=>'nw', -padx= +>70); my $frm_name2 = $mw -> Frame( -relief=> 'groove', -borderwidth => 5,-background => 'black') ->pack(-side => 'top',-fill => 'x'); my $expenseentry = $frm_name2->Entry(-width=> 10, -textvar => \$chosen +_item) -> pack(-side =>'left',-anchor =>'nw'); MainLoop; # Subroutines sub addtext { my ($item) = @_; $chosen_item = $item; }

Using the command -textvar => \$chosen_item links whatever is assigned to $chosen_item to the Entry widget.  (You might even consider maken it a Label widget, so that the user can't change its contents; you could use the -relief and -border options to make it look just like an Entry widget, but without being directly modifiable).

The line:

$expensemb->command(-label => $item, -command => sub { addtext($it +em) });

packs each text item into the Menubutton, and associates that text with a callback to addtext.  You could even certainly do:

$expensemb->command(-label => $item, -command => sub { $chosen_ite +m = $item });

if you wanted to do nothing other than assign the Entry text, but I made it into a separate subroutine in case you need to take other actions when the user makes a selection.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re: Tk - Menuitems -grab text by liverpole
in thread Tk - Menuitems -grab text by props

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.