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

I am trying to put a menubutton on a menubar that will exit the program when clicked (as opposed to having a dropdown menu). I have the menbar created, added the manubutton, but I can't figure out how to bind an exit to the menubutton itself. Right now, I have a single item drop down menu that the user has to click to exit. Is there a way to simply click the menubutton and have the program exit?

Replies are listed 'Best First'.
Re: TK menu question
by Argel (Prior) on Jan 26, 2006 at 23:36 UTC
    I think this is what you want (specifically line 6).
    my %tk; $tk{top} = MainWindow->new(); $tk{menubar} = $tk{top}->Menu; $tk{top}->configure( -menu => $tk{menubar} ); $tk{menu_file} = $tk{menubar}->cascade( -label => '~File' ); $tk{menu_exit} = $tk{menubar}->command( -label => '~Exit', -command = +> sub { Tk::exit(0); } );
    Updated: Changed "my $tk;" to "my %tk;"
      Am I missing something obvious? When I run the above code, nothing happens (no window creation, etc). I added use Tk; to the code. Still nothing. This looks like a much better way to go...if I can get it to work....thoughts? Neevvveeerrrrmind..... forgot MainLoop()....
        My apologies for the confusion. The first few lines are there just so that readers can understand the variables I'm using. it wasn't meant to be a fully working code sample.