Hey all,
You may remember I had a node up last night on this question and got a few replies. Its not the same question at all but its on the same script.
To refres your memory I'm in the process of making my own script editor. I.e. A text editor with a few extra functions. But I'm getting heldup on the eazy stuff. I've only a few questions that I can't seem to get at the moment but I'm sure that there'll be more. Thats why I started a new node. What I need to know is When you open a file to make the name appear up near the title.( I can either get just the Title - , or Title - $filename) And when in the open\save window, when you click on an item in the ListBox make the name of it appear in the Entry line named $name.

Heres the code:
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); }
And thats it.
This is my first 'proper' script if you get my meaning and
I would appriciate as much help as possible.
Also if anyone has any suggestions for things to add in or anything like that to make it more efficient or what ever.
Thanks for all the help so far.

All the Best, Eoin...

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.