Always use strict and warnings. With that, you'd have gotten warnings like Variable "$open" will not stay shared, which might have been a hint that there's still something wrong with the scoping of the variable $open.
The problem is in particular that you've declared $open locally to the callback function push_button, and that you've declared the other callback functions locally to that function (which I had only realized after having indented your code reasonably...). Perl does not have local subroutines, and if you declare named subs within other subs, they're essentially parsed as if they were declared top-level. Hence the scope issue.
Here's a stripped down version (with "minor" edits to make it actually runnable...), which uses real global variables for $open and $te (for which the same issues apply), so that they can be shared across various callback routines.
#!/usr/bin/perl -w use strict; use Tk; my $open; my $te; # Entry Window my $mw = new MainWindow; # The START button: my $button = $mw -> Button(-text => "Start",-command=>\&push_button)-> +pack(); MainLoop; sub push_button { my $mw = new MainWindow; $mw -> geometry ("1200x600"); # Menu bar $mw->configure(-menu => my $menubar = $mw->Menu, -background => 'white'); my $file = $menubar->cascade(-label => '~File'); my $edit = $menubar->cascade(-label => '~Edit'); my $help = $menubar->cascade(-label => '~Help'); $mw-> Button (-text =>'Open', -command =>\&open_file)->place(-x=>2 +40, -y=>35); $mw-> Button (-text =>'Get Statistics', -command =>\&get_statistic +s)->place(-x=>320, -y=>35); $te = $mw->Scrolled('TextUndo')->place(-x=>240, -y=>70); MainLoop; } sub open_file { $open = $mw->getOpenFile( #-filetypes => $types_OPEN, -defaultextension => '.sff' ); $te->Load($open); } sub get_statistics { my $fastafile= $open; print STDERR "selected file: $fastafile\n"; }
A few more comments:
In reply to Re^9: Perl tk - How to integrate external scripts
by Eliya
in thread Perl tk - How to integrate external scripts
by Giorgio C
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |