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


In reply to (bbfu) Re: A question about displaying images by bbfu
in thread A question about displaying images by Qitan

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.