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

I am having issues with defining the width and height of the frame widget "$mini" in the following code. It is an embedded frame that is created to display an image when the grab() function is called. The frame is placed in a scrolling frame named "$frame2_1". When the frame is created it appears in the center of $frame2_1 with an inch padding(?) on both sides?

I would like to align the widget to the left side of the frame and resize to something else. However, configure(-width ##) does not work? I can move the widgets inside around using place() but nothing I do will increase/change the size of the frame $mini?

Please forgive me dumping the entire code here (~120 lines). It would be nice if I could display a picture of what the gui is doing.

#!/usr/bin/perl -w use strict; use Tk; use Tk::WinPhoto; use Tk::JPEG; #Global variables my $img_count = 0; #number of images displayed my @mini; #array of frames created when image is grabbed #Main window parameters my $mw = MainWindow->new(); $mw->minsize(qw(670 510)); $mw->configure(-background=>'gray'); $mw->title("Screen Capture GUI"); 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('Frame',-scrollbars=> "e"); $frame2_1 -> place(-x=>10,-y=>50, -width=>650, -height=>400 ); MainLoop(); ###################################################################### +#### ###################################################################### +#### sub Grab(){ #Takes picture and makes thumbnail to display in mini frame ###################################################################### +#### #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 230X230 $fname -resize 230x230 $fname2"); ###################################################################### +#### $img_count++; #Frame packed in scrolling Frame $mini[$img_count] = $frame2_1->Frame(-background=>'#3300ff'); $mini[$img_count] -> configure(-relief => 'groove', -borderwidth => 2) +; $mini[$img_count] ->pack(); #need to create new frame to hold contents #stupid pack needs to create area to display things, this works but no +t quite right? my $dummy = $mini[$img_count]->Canvas(); $dummy -> create('rectangle', 0,0,500,300, -fill=>"black"); $dummy -> pack(); #items for mini frame my $img_label = $mini[$img_count]->Label(-text=>"Image $img_count"); $img_label -> place(-x=>5,-y=>5); my $pic_location = $mini[$img_count]->Label(-text=>"Pathname:"); $pic_location -> place(-x=>5,-y=>25 ); my $pic_fname = $mini[$img_count]->Entry(-width=>50,-textvariable=>"$f +name"); $pic_fname -> place(-x=>70,-y=>25 ); my $pic = $mini[$img_count]->Photo( -file =>"$fname2"); my $f =$mini[$img_count]->Label(-image => $pic); $f -> place(-x=>5,-y=>50 ); my $i = $img_count; my $but_delete = $mini[$img_count] ->Button( -text => "Delete Image", +-command => sub { \&Delete($mini[$i], $i) } ); $but_delete -> place(-x=>5,-y=>240 ); my $blank1 = $frame2_1->Label(-text=>""); $blank1 ->pack(); #Removes items from scrolling frame and replaces them with most recent + frame created at top ################################################ my $k = $img_count-1; if($img_count>=2){ while($k!=0){ $mini[$k]->packForget; $k--; } $k=$img_count; while($k!=0){ $mini[$k]->pack(); $k--; } } ################################################ #print "i =$img_count :: mini is $mini[$img_count]\n"; } #close Grab() ###################################################################### +#### ###################################################################### +#### sub Delete(){ my ($fn, $i) =@_; #if only one image displayed if ($img_count == 1){$fn ->destroy; $img_count--; return;} #print "Image $i deleted is $fn\n"; $fn ->destroy; #Deleted image now need to reorder array @mini[] splice(@mini,$i,1); $img_count--; }

Replies are listed 'Best First'.
Re: Unable to resize embedded frame in perl/Tk
by zentara (Cardinal) on Mar 28, 2011 at 17:06 UTC
    Hi, your script seems to work as described. It takes a sucession of Grab Screen's to lay in images in the scrolled Frame.

    I will mention that a Scrolled Pane is far preferable to a Scrolled Frame. I would switch to a scrolled Pane for your main container, before you go much further. Frames are very crude containers, and I don't know if they can be resized without a packForget and repack. What you might want to do limit the scrollregions, instead of attempting a resize, if that makes any sense to you.

    Here is a simple scrolled Pane example:

    #!/usr/bin/perl use strict; use Tk; use Tk::Pane; my $mw = MainWindow->new; $mw->geometry('400x250'); my $mwf = $mw->Scrolled('Pane', -scrollbars=>'osoe', -sticky=>'nwse', )->pack(-expand=>1, -fill=>'both'); my $f1 = $mwf->Frame()->pack(-expand=>1,-fill=>'both'); my $f2 = $mwf->Frame()->pack(-expand=>1,-fill=>'both'); my %canv; for (0..4){ $canv{$_}{'obj'} = $f1->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'white', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left' ,-padx=>10,-pady=>10, -expand=>1, -fill=>'bo +th'); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); } for (5..9){ $canv{$_}{'obj'} = $f2->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'white', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left', -padx=>10,-pady=>10 ,-expand=>1, -fill=>'bo +th'); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); } MainLoop();

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh