Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

TK Submenus

by PilotinControl (Pilgrim)
on Oct 28, 2013 at 14:25 UTC ( #1059989=perlquestion: print w/replies, xml ) Need Help??
PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:

Morning Greetings Brother Monks, Today's question is as follow: I have two levels of sub menus and now I've created a third level of submenus. I have no problems going from submenu one back to the Toplevel menu or going from submenu two back to submenu one it is when submenu three goes back to submenu two is the issue. Yes I do use "strict, warnings and diagnostics" at the beginning of my code. Code and Error posted below thanks in advance!

sub addmanifest { my $perInfo9 = {NAME => '', TOWNS => '', TRAILER => ''}; my $addmn = $mw->Toplevel(); $addmn->group($mw); $addmn->resizable(0,0); # Create the main window $addmn->configure(-title=>'Add Manifest'); $addmn->geometry('285x270+0+0'); my $personInfo9 = $addtmn->Frame()->pack(-side=>'top',-fill=>'x'); my $personLeft9 = $personInfo9->Frame()->pack(-side=>'left',-fill=>' +x'); my $personRight9 = $personInfo9->Frame()->pack(-side=>'left',-fill=>' +x',-padx=>20,-pady=>20); $personLeft9->Label(-text=>'Manifest Information')->pack(); $personLeft9->Label(-text=>'')->pack(); $personLeft9->Label(-text=>'Manifest Name')->pack(); $personLeft9->Label(-text=>'Manifest Towns')->pack(); $personLeft9->Label(-text=>'Manifest Trailer')->pack(); $personRight9->Label(-text=>'')->pack(); $personRight9->Label(-text=>'')->pack(); $personRight9->Entry(-width=>20,-borderwidth=>2, -relief=>'sunken',-textvariable=>\$perInfo9->{NAME})->pack(); $personRight9->Entry(-width=>20,-borderwidth=>2, -relief=>'sunken',-textvariable=>\$perInfo9->{TOWNS})->pack(); $personRight9->Entry(-width=>20,-borderwidth=>2, -relief=>'sunken',-textvariable=>\$perInfo9->{TRAILER})->pack(); my $saveFrame9 = $addmn->Frame()->pack(-side=>'top',-fill=>'x'); $saveFrame9->Button(-text => 'Add Manifest', -command => sub { open(OUT,">>DATA/manifestdata.txt"); print OUT "" . $perInfo9->{NAME} . ":"; print OUT "" . $perInfo9->{TOWNS} . ":"; print OUT "" . $perInfo9->{TRAILER} . "\n"; close(OUT); sleep 2; $addmn->withdraw; $mm->deiconify; # THIS IS SUB MENU TWO IT HAS TO BE SUBMENU THREE HOW +EVER THE BELOW ERROR OCCURS when $mm is used, I have to use $opsm in +order for it to work correctly } )->grid(-row, 2, -column, 0, -sticky => 'nesw'); $balloon->attach($saveFrame9, -balloonmsg => "Return To Add Manifest") +; } # END __ERROR__ Tk::Error: Can't call method "deiconify" on an undefined value at C:\U +SER\PERL\PROGRAM\ line 3995. Tk callback for .toplevel3.frame1.button Tk::__ANON__ at C:/Perl/site/lib/ line 250 Tk::Button::Invoke at C:/Perl/site/lib/Tk/ line 200 <Key-Return> (command bound to event)

Replies are listed 'Best First'.
Re: TK Submenus
by hdb (Monsignor) on Oct 28, 2013 at 14:33 UTC

    The error message says that $opsm is undefined. As far as I can see it is not declared nor defined anywhere in your code. If you use strict; it must be defined somewhere but is not set.

    Depending on the rest of your code, you might also get a closure effect, ie when you first call addmanifest the variable $opsm is undefined and enclosed in your anonymous callback sub. So even if you set a value later, it will not be used here.

      Hello HDB here is the sub routine that is the second sub menu that calls the third sub menu:

      sub manifest { if ( !Exists( $mm ) ) { my $mm = $mw->Toplevel(); $mm->group($mw); $mm->resizable(0,0); my $mmframe2 = $mm->Frame()->pack( -side => 'right', -fill => 'both', + -anchor, 'e'); my $mmframe = $mm->Frame()->pack( -side => 'left', -fill => 'both', + -anchor, 'w'); $mm->geometry('400x125+0+0'); $mm->title( "Manifest Management Menu" ); my $mmbtn1 = $mmframe->Button( -text, 'Add A Manifest', -command => +sub { &addmanifest; $mm->iconify;})->grid( -row, 0, -column, 0, - +sticky => 'nsew'); $balloon->attach($mmbtn1, -balloonmsg => "Add A Manifest"); my $mmbtn2 = $mmframe->Button( -text, 'Edit A Manifest', -command => + sub { &editmanifest; $mm->iconify;})->grid( -row, 1, -column, 0, +-sticky => 'nsew'); $balloon->attach($mmbtn2, -balloonmsg => "Edit A Manifest"); my $mmbtn3 = $mmframe->Button( -text, 'Delete A Manifest', -command +=> sub { &deletemanifest; $mm->iconify;})->grid( -row, 2, -column, 0 +, -sticky => 'nsew'); $balloon->attach($mmbtn3, -balloonmsg => "Delete A Manifest"); my $mmbtn4 = $mmframe->Button( -text, 'View All Manifests', -command + => sub { &viewallmanifests; $tmm->iconify;})->grid( -row, 3, -column +, 0, -sticky => 'nsew'); $balloon->attach($mmbtn4, -balloonmsg => "View All Manifests"); my $mmbtn5 = $mmframe2->Button( -text, 'View Manifests By Name', -co +mmand => sub { &viewmanifestbyname; $mm->iconify;})->grid( -row, 0, - +column, 3, -sticky => 'nsew'); $balloon->attach($mmbtn5, -balloonmsg => "View Manifests By Name"); my $mmbtn6 = $mmframe2->Button( -text, 'Total Manifest Count', -comma +nd => sub { &totalmanifestcount; $mm->iconify;})->grid( -row, 1, -col +umn, 3, -sticky => 'nsew'); $balloon->attach($mmbtn6, -balloonmsg => "Total Manifest Count"); my $mmbtn7 = $mmframe2->Button( -text, 'Return To Ops Menu', -command + => sub { $mm->withdraw; $opsm->deiconify;})->grid( -row, 2, -column, + 3, -sticky => 'nsew'); $balloon->attach($mmbtn7, -balloonmsg => "Return To Ops Menu"); } else { $mm->deiconify(); $mm->raise(); } } # END MANIFEST MENU

        And where do you declare and assign some value to variable $opsm?

Re: TK Submenus (Tk::Menu , global variables/ spirit of strict)
by Anonymous Monk on Oct 29, 2013 at 00:53 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1059989]
Approved by hdb
and a kettle whistles...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-04-22 11:39 GMT
Find Nodes?
    Voting Booth?