And thats it.use strict; use warnings; use Tk; my $filename; my $ListBox; my $name; my $saveas; my $Listbox; my $mw=MainWindow->new(-title => 'TextEd - ' . $filename); $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(-title => 'Open...'); my $tf = $open->Frame; my $bf = $open->Frame; ($ListBox) = $tf->Scrolled('Listbox', -height => '10', -width => '20', -scrollbars => 'e', ); opendir DIR, "."; $ListBox->insert('end', grep { -f $_ && -r $_ } readdir DIR); close DIR; $name = $bf->Entry(-textvariable => \$filename); my $button = $bf->Button( -command => \&load, -text => 'Open'); $tf->pack(-side => 'top'); $bf->pack(-side => 'bottom'); $ListBox->pack(qw/-side left -fill both -expand 1/); $name->pack(-anchor => 's'); $button->pack(-anchor => 'se'); } sub load{ my ($index) = $ListBox->curselection(); $filename = $ListBox->get($index); $InputText->Load( $filename ); (my $script = $0) =~ s,.*(\/|\\),,; } sub save_file{ my $save = $mw->Toplevel(-title => 'Save...'); my $tf = $save->Frame; my $bf = $save->Frame; ($ListBox) = $tf->Scrolled('Listbox', -height => '10', -width => '20', -scrollbars => 'e', ); opendir DIR, "."; $ListBox->insert('end', grep { -f $_ && -r $_ } readdir DIR); close DIR; $name = $bf->Entry(-textvariable => \$filename); my $button = $bf->Button( -command => \&save, -text => 'Save'); $tf->pack(-side => 'top'); $bf->pack(-side => 'bottom'); $ListBox->pack(qw/-side left -fill both -expand 1/); $name->pack(-anchor => 's'); $button->pack(-anchor => 'se'); } sub save{ $InputText->Save( $filename ); } sub entry{ my ($index) = $ListBox->curselection(); $filename = $ListBox->get($index); }
If everything seems to be going well, you obviously don't know what the hell is going on.
In reply to Binding an action to an item in a Listbox by eoin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |