Hi,
I am creating a screen capture gui using perl/TK. The script will capture a screen using imageMagick. I then display the captured image in my main window. I would like to delete the image and remove it from the display. I tried using destroy(), however I get the following error when I attempt to delete:
Tk::Error: Can't call method "destroy" without a package or object re
+ference at ./Capture4.pl line 80.
Tk callback for .frame.pane.frame.frame.button
Tk::__ANON__ at /usr/lib/perl5/Tk.pm line 250
Tk::Button::butUp at /usr/lib/perl5/Tk/Button.pm line 175
<ButtonRelease-1>
(command bound to event)
I would like the window to redraw without the image. Perhaps there is a better way to do this? Any help would be appreciated.
Oh! here is the code to the script
#!/usr/bin/perl -w
use strict;
use Tk;
use Tk::WinPhoto;
use Tk::JPEG;
use Tk::Pane;
my $mw = MainWindow->new();
$mw->minsize(qw(670 510));
$mw->configure(-background=>'gray');
$mw->title("Screen Capture GUI");
my $img_count = 0;
my $but_capture = $mw->Button( -text => "Capture Screen", -command =>
+sub { \&Grab() } );
$but_capture -> place(-x=>10,-y=>5, -width=>650);
my $exit = $mw->Button( -text => "Exit", -command => sub { exit } );
$exit -> place(-x=>560,-y=>460, -width=>100);
my $frame2_1 = $mw->Scrolled(qw/Pane -scrollbars ose/);
$frame2_1 -> place(-x=>10,-y=>50, -width=>650, -height=>400 );
MainLoop();
sub Grab(){
######################################################################
+####
#Creating file handle and taking picture
my $tim = time();
my $fname = "/tmp/".$tim.".jpg";
print "$fname\n";
system("import -frame $fname");
#resize to display in window
my $fname2=$fname."sm.jpg";
system("convert -size 350X350 $fname -resize 350x350 $fname2");
######################################################################
+####
$img_count++;
my $mini;
#Frame packed in scrolling Pane
$mini = $frame2_1->Frame(-background=>'#3300ff')->pack(-anchor => 'w',
+ -fill =>"x");
#create new frame to hold new image contents
my $img_label = $mini->Label(-text=>"Image $img_count");
$img_label ->pack();
my $pic_location = $mini->Label(-text=>"Pathname:");
$pic_location ->pack();
my $pic_fname = $mini->Entry(-width=>50,-textvariable=>"$fname");
$pic_fname ->pack();
my $pic = $mini->Photo( -file =>"$fname2");
my $f =$mini->Label(-image => $pic);
$f ->pack();
my $but_delete = $mini ->Button( -text => "Delete Image", -command =>
+sub { \&Delete($mini) } );
$but_delete -> pack();
my $blank1 = $frame2_1->Label(-text=>"");
$blank1 ->pack();
}
sub Delete(){
my $fn =@_;
$fn ->destroy;
}