Hey all, I'm in the process of making my own script editor. When finished it'll have debug funcs. etc, but its still in its early stages. I'm having a problem with the menubar. I can't get it to load its new windows. E.g. If i click on Open in the File menu, the window for opening a new file should pop up.
Guess what... It doesn't.
Heres the error I get when I click on Open.
Assuming 'require Tk::TopLevel;' at txt.pl line 75 Subroutine Tk_cmd redefined at C:/Perl/site/lib/Tk/TopLevel.pm line 14 + (#2) (W redefine) You redefined a subroutine. To suppress this warning +, say { no warnings 'redefine'; eval "sub name { ... }"; } Subroutine CreateOptions redefined at C:/Perl/site/lib/Tk/TopLevel.pm +line 17 (# 2) Subroutine Populate redefined at C:/Perl/site/lib/Tk/TopLevel.pm line +22 (#2) Subroutine Icon redefined at C:/Perl/site/lib/Tk/TopLevel.pm line 29 ( +#2) Subroutine menu redefined at C:/Perl/site/lib/Tk/TopLevel.pm line 64 ( +#2) Subroutine Tk::Widget::Toplevel redefined at C:/Perl/site/lib/Tk/Widge +t.pm line 247 (#2) Tk::Error: Failed to AUTOLOAD 'Tk::Widget::TopLevel' at txt.pl line 75 [\&main::open_file] (menu invoke)
I'm not sure about any of it. Heres the code
#!/usr/bin/perl use warnings; use diagnostics; use Tk 800.000; use Tk::Frame; use Tk::TextUndo; use Tk::Text; use Tk::Scrollbar; use Tk::Menu; use Tk::Menubutton; use Tk::Adjuster; use Tk::DialogBox; 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; $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,.*(\/|\\),,; }

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 How can you redefine a subroutine?? 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.