Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Tk:::Optionmenu startup displaying the optionlist

by Ray Smith (Beadle)
on Feb 03, 2015 at 17:48 UTC ( [id://1115424]=perlquestion: print w/replies, xml ) Need Help??

Ray Smith has asked for the wisdom of the Perl Monks concerning the following question:

Is there a method to have Tk::Optionmenu start displaying the option list without having the user first click the button?

Question 2: Why does the Optionmenu callback function (localCall below) get called before the user click of Optionmenu button? Please look at my workaround.

Thanks

!/usr/bin/perl -w use strict; use warnings; # teest Tk::Menuoption use Tk; use Tk::Optionmenu; my $mw = new MainWindow; my $baseFrame = $mw->Frame()->pack( -side=>'top', -fill=>'both', -expand=>0); my $name_text = "phone name"; my $phoneNo = 51206; $baseFrame->Button(-text=>$phoneNo, -relief=>'flat', -cursor=>'hand1', -activeforeground=>'blue', -activebackground=>'white', -command => sub {phoneCmds( $baseFrame, $phoneNo);}, )->pack(-side=>'left'); my $cmdsFrame; my $cm; sub phoneCmds { my ( $baseFrame, $caller, ) = @_; my $deviceDN = $caller; print "caller(deviceDN)=$deviceDN\n"; $cmdsFrame = $baseFrame->Frame( )->pack( -side=>'left', -fill=>'both', -expand=>0); my @callees = qw/46001 46002 46003 46004/; my $callee; $cm = $cmdsFrame->Optionmenu(- -variable =>\$callee, -options => [@callees], -command => [\&localCall, $caller], ); $cm->pack(); } sub localCall { my ( $caller, $callee, ) = @_; return if !defined($callee); return if !defined($cm); print "localCall: caller=$caller callee = $callee\n"; $cm->destroy() if $cm && $cm->exists(); $cm = undef; $cmdsFrame->destroy() if $cmdsFrame && $cmdsFrame->exists(); # $cmdsFrame = undef; } MainLoop;

Replies are listed 'Best First'.
Re: Tk:::Optionmenu startup displaying the optionlist ( tk optionmenu bug , event generate)
by Anonymous Monk on Feb 04, 2015 at 00:45 UTC

    Is there a method to have Tk::Optionmenu start displaying the option list without having the user first click the button?

    Yes, generate a tk event, or call the appropriate Tk::Optionmenu method directly, Tk::WidgetDump might help you figure stuff out

    or, use a widget other than Tk::Optionmenu, maybe a Tk::Listbox or something else, like a frame or panel of buttons that you create

    Question 2: Why does the Optionmenu callback function (localCall below) get called before the user click of Optionmenu button?

    What does the documentation say about it? https://metacpan.org/pod/Tk::Optionmenu#command

    I would assume because the Tk::Optionmenu calls it, because its written that way :) ... and this is probably a bug but it might be a feature; -options is loaded and a default option is selected after the -command is bound ... so the -command callback gets invoked

    Please look at my workaround.

    Yup, akward :) I don't recognize any part of the program as a workaround

    In each callback you can use $Tk::event and $Tk::widget ... combine with ->parent, and no need for some of those closures

      $cm->update; $cm->Post;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1115424]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-24 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found