in reply to How can you redefine a subroutine??
The big problem is, that you wrote TopLevel instead of Toplevel
This is a quick shoot for your script:
As you can see, you just have to use Tk and all the other required modules need not to be used here.use strict; use warnings; use Tk; my $listbox; my $mw=MainWindow->new; $mw->geometry('800x600'); my $menu_bar = $mw->Frame(); my $rf = $mw->Frame; my $search_mb = $menu_bar->Menubutton('-text' => 'File', '-relief' => 'raised', '-borderwidth' => 2, )->pack('-side' => 'left', '-padx' => 2 ); $search_mb->command('-label' => 'Open', '-accelerator' => 'Ctrl+o', '-underline' => 0, '-command' => \&open_file ); $search_mb->command('-label' => 'Save', '-accelerator' => 'Ctrl+s', '-underline' => 0, '-command' => \&save_file ); $search_mb->command('-label' => 'Close', '-accelerator' => 'Ctrl+x', '-underline' => 0, '-command' => \&close_file ); $search_mb->command('-label' => 'Exit', '-accelerator' => 'Ctrl+q', '-underline' => 0, '-command' => [$mw => 'destroy'] ); my($InputText) = $rf->Scrolled('TextUndo', -height => '1', -width => '1', -scrollbars => 'osoe', ); $menu_bar->pack(-anchor => 'nw'); $rf->pack(qw/-side right -fill both -expand 1/); $InputText->pack(qw/-side top -fill both -expand 1/); MainLoop; sub open_file{ my $open = $mw->Toplevel; $open->geometry('400x550'); my $tf = $open->Frame; my $bf = $open->Frame; $listbox = $tf->Listbox(-height => '10', -selectmode => 'browse', -width => '40', -relief => 'sunken', -setgrid => '1'); $listbox->delete('0.1', 'end'); opendir DIR, "."; $listbox->insert('end', grep { -f $_ && -r $_ } readdir DIR); close DIR; my $button = $bf->Button( -command => \&load, -text => 'Open'); $tf->pack; $bf->pack; $button->pack(-anchor => 'se'); } sub load{ my ($index) = $listbox->curselection(); my $filename = $listbox->get($index); $InputText->Load( $filename ); (my $script = $0) =~ s,.*(\/|\\),,; }
Hope this helps.
----------------------------------- --the good, the bad and the physi-- -----------------------------------
|
|---|