Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: widget box problem in tk

by Anonymous Monk
on May 12, 2014 at 03:00 UTC ( [id://1085739]=note: print w/replies, xml ) Need Help??


in reply to widget box problem in tk

... Reopen it using same button It neither Deletes previous entry nor takes new Entry ...

Yup, typical coping with scoping issue ( life cycle of variables ), see lots and lots links in Re^2: Perl Gtk2 - ->destroy() is Not Causing the Script to Exit

links like Re^2: Border-less main window (Alt+F4 Ctrl+C , Re: Perk Tk - how to send a value from a subroutine back to the main program using Button (without MainLoop), Re: Perl tk FindNext in a text widget, Confused by variable scope in Tk::Wizard

Then write Tk callbacks all lexically scoped and not-memory leaking with no nested subs ever :) avoid nested subs and closures because nested named subs because they're closures

Also, meaningful variable/function names are good :)

Here is your program slightly fixed up (so it doesn't error message), could use more fixing (for readability/understandability...) ... if you don't understand the changes I made start with a pencil & paper description of your program:)

#!/usr/bin/perl -- #~ #~ 2014-05-11-19:59:34 #~ ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use Tk; use strict; Main( @ARGV ); exit( 0 ); sub Main { my $mw = MainWindow->new; $mw->geometry( "200x300" ); $mw->title( "MAIN WINDOW" ); my $button_frame1 = $mw->Frame()->pack( -side => "top" ); $button_frame1->Button( -text => "GI EXTRACTOR", -command => \&win +dow1 ) ->pack(); MainLoop; } ## end sub Main sub window1 { my $mw = MainWindow->new; $mw->geometry( "700x700" ); $mw->title( "GI EXTRACTOR WINDOW" ); my $button_frame1 = $mw->Frame()->pack( -side => "top" ); my $lname1; ## eew var name:) #~ $button_frame1->Button(-text => "Browse File", -command => \&up +date_output1)->pack(-side => "top"); $button_frame1->Button( -text => "Browse File", -command => [ \&update_output1, $mw, \$lname1 ] )->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 => + "bottom"); my $output_frame1 = $mw->Frame()->pack( -side => "bottom" ); my $output_scroll1 = $output_frame1->Scrollbar(); my $output_text1 = $output_frame1->Text( -yscrollcommand => [ 'set', $output_scroll +1 ] ); $output_scroll1->configure( -command => [ 'yview', $output_text1 ] + ); $output_scroll1->pack( -side => "right", -expand => "no", -fill => + "y" ); $output_text1->pack(); $b_f1->Button( -text => "Ok", -command => [ \&u_o1, $output_text1, \$lname1 ] )->pack( -side => "bottom" ); } ## end sub window1 sub update_output1 { #~ my $button_frame1 = $mw->getOpenFile(); #~ my $button_frame1 = shift( @_ )->getOpenFile(); my( $mmmwww, $lnameref ) = @_; my $button_frame1 = $mmmwww->getOpenFile(); $$lnameref = $button_frame1; } sub u_o1 { my( $output_text1, $lnameref ) = @_; my $output1; use autodie; #~ open( FH, "<$lname1" ); open my( $fh ), '<', $$lnameref; 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 ); } ## end sub u_o1

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

I'd be very interested to learn what keywords you searched for

Replies are listed 'Best First'.
Re^2: widget box problem in tk
by prince26121991 (Novice) on May 12, 2014 at 04:25 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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1085739]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-19 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found