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; }

In reply to Issue destroying image using perl/TK by nikwasi

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.