in reply to A question about displaying images

To show a window without the title-bar in Perl/Tk, you would use the $toplevel->overrideredirect(1) method. (Update: FYI, overrideredirect is documented under Tk::Wm.) Note that if you do so, the user can't move the window around any more, as they can't drag the title-bar. So you should be careful about window positioning, or give them some other way to move the window (such as dragging anywhere on the image, or providing a "drag area").

Generally, if you just tell Tk to use the new image, it will update the screen appropriately, and without flicker. (At least, it doesn't have any flicker for me. Let me know if you get any.)

The following code should do what you want.

#!/win2k/Perl/bin/perl use warnings; use strict; use Tk; our $CurrentImage = -1; our @Images = qw( D:/Wallpapers/tmp/wide.gif D:/Wallpapers/tmp/deepsea.gif D:/Wallpapers/tmp/flea.gif D:/Wallpapers/tmp/forest.gif ); our $MainWin = Tk::MainWindow->new(); our $ImgLabel = $MainWin->Label()->pack; $MainWin->overrideredirect(1); # Remove border and title bar from win +dow $MainWin->bind('<KeyPress-Escape>', [$MainWin, 'destroy']); $MainWin->bind('<KeyPress-minus>', \&prev_image); $MainWin->bind('<KeyPress-plus>', \&next_image); load_images(); next_image(); center($MainWin); MainLoop; sub next_image { $CurrentImage = ++$CurrentImage % @Images; $ImgLabel->configure(-image => $Images[$CurrentImage]); } sub prev_image { $CurrentImage = $#Images if(--$CurrentImage < 0); $ImgLabel->configure(-image => $Images[$CurrentImage]); } sub load_images { for my $image (@Images) { # Replace image filename w/ loaded image $image = $MainWin->Photo( -file => $image, -format => 'gif', ); } } sub center { my $win = shift; $win->withdraw; # Hide the window while we move it about $win->update; # Make sure width and height are current # Center window $win->geometry( '+' . int( ($win->screenwidth - $win->width) / 2 ) . '+' . int( ($win->screenheight - $win->height) / 2 ) ); $win->deiconify; # Show the window again }

bbfu
Black flowers blossum
Fearless on my breath

Replies are listed 'Best First'.
Re: (bbfu) Re: A question about displaying images
by Qitan (Novice) on Jan 04, 2003 at 19:42 UTC
    Thanks, I think this technique will work perfectly for what I'm working on.

    Thanks again,

    Butch