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

I am beginner in perl Tk Sometime ago I asked even a book for perl Tk but you people suggested me to go through online documentation rather than a book coz documentation are more up2date in compare of a book so here is what I made
use Tk; use strict; my $mw = MainWindow->new; $mw->geometry("200x300"); $mw->title("MAIN WINDOW"); my $lname1; my $button_frame1 = $mw->Frame()->pack(-side => "top"); $button_frame1->Button(-text => "GI EXTRACTOR", -command => \&window1) +->pack(); sub window1 { my $mw = MainWindow->new; $mw->geometry("700x700"); $mw->title("GI EXTRACTOR WINDOW"); my $button_frame1 = $mw->Frame()->pack(-side => "top"); $button_frame1->Button(-text => "Browse File", -command => \&updat +e_output1)->pack(-side => "top"); my $bf1 = $mw->Frame()->pack(-side => "top"); $bf1->Label(-text => "You Have Selected The Following File")->pack +(-side => "left"); $bf1->Entry(-bg=>'red',-textvariable => \$lname1)->pack(-side => " +left"); my $b_f1 = $mw->Frame()->pack(-side => "top"); $b_f1->Button(-text => "Ok", -command => \&u_o1)->pack(-side => "b +ottom"); my $output_frame1 = $mw->Frame()->pack(-side => "bottom"); my $output_scroll1 = $output_frame1->Scrollbar(); my $output_text1 = $output_frame1->Text(-yscrollcommand => ['set', + $output_scroll1]); $output_scroll1->configure(-command => ['yview', $output_text1]); $output_scroll1->pack(-side => "right", -expand => "no", -fill => +"y"); $output_text1->pack(); sub update_output1 { my $button_frame1 = $mw->getOpenFile(); $lname1=$button_frame1; } sub u_o1 { my $output1; open(FH,"<$lname1"); while(my $_=<FH> ) { if($_=~/^>gi/) { my@arr=split(/\|/,$_); $output1=$arr[0].$arr[1]; } } close(FH); $output_text1->delete('0.0', 'end'); $output_text1->insert("end", $output1); } } MainLoop;

This is a simple Tk program which opens a Main Window having a button called"GI Extractor" After clicking on it gives a new window" GI Extractor WINDOW" having total 5 widget

1.Browse file(which call getOpenFile()); 2.label (shows hardcoded text); 3.ENTRY(which show address of selected file); 4.ok button (which call mechanism of this program); 5.scrollbox(which shows ouput);

Now when I click on GI Extractorbutton in "Main Window", It works like a charm

But when once I close "GI EXTRACTOR WINDOW"and Reopen it using same button It neither Deletes previous entry nor takes new Entry

Instead of it gives a very long error in Command line

Hoping for a good reply with some example code coz I searching for this problem since last 5 hour please help

Replies are listed 'Best First'.
Re: widget box problem in tk
by Anonymous Monk on May 12, 2014 at 03:00 UTC
      Thank you So Much Sir! Well I'll read All these link and will try to understand what change u exactly made! Ur program were not working perfectly I made a change in it :p
      open my( $fh ), '<', $$lnameref; while( my $_ = <FH> )
      open my( $fh ), '<', $$lnameref; while( my $_ = <$fh> )
      Now It's Perfect! It's been whole night spent on it thats why am sleepy now but if der will be some problem in any line thn I'll get back to u on it! u asked for terms! here are some of them! http://prntscr.com/3ig7pl Thank You So Much!
Re: widget box problem in tk
by ww (Archbishop) on May 12, 2014 at 12:18 UTC

    Trying to understand the error would have helped you.

    C:\>1085723.pl Variable "$mw" will not stay shared at 1085723.pl line 42. Variable "$output_text1" will not stay shared at 1085723.pl line 60.
    and trying to actually execute the file would have added critical information:
    Use of uninitialized value $lname1 in concatenation (.) or string at 1 +085723.pl line 48. readline() on closed filehandle FH at 1085723.pl line 49.

    Careful study of the "very long error in Command line" will help you; quoting it will help us to help you.


    Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
    1. code
    2. verbatim error and/or warning messages
    3. a coherent explanation of what "doesn't work actually means.

    check Ln42!