Fellow monks,

I'm still relatively new to the world of Win32::GUI and so I'm trying to port a working Tk stock price app that I wrote. BBFU was kind enough to point me to the direction of Timer for the timed calling of a subroutine, but now I'm stumped by the actual act of refreshing text labels.

In my Tk program, I write the labels, and when I go to refresh, I replace them all with blank lines, then rewrite them. Maybe not the best way to do it, but in Tk I'm not noticing any delay in the "erasing" and the "rewriting".

My first thought was to write a small test app to see if I could figure this out, but I'm stumped as to why once the string is at it's max length, it won't "erase" the extra bits when fed a smaller string.

use strict; use Win32::GUI(); my $interval = 100; my $main = Win32::GUI::Window->new( -name => 'Main', -width => 150, -height => 100, -onTimer => \&redraw_Timer, ); $main->AddTimer( "redraw_Timer", $interval); $main->Show(); Win32::GUI::Dialog(); sub Main_Terminate { -1; } sub redraw_Timer{ my $temp = localtime; return $main->AddLabel(-text => $temp); }

Now when translating this to my stock price app, I've got 8-10 stocks that I'm watching, and obviously as prices flucuate, I'm going to be stung by having something at +.90 perhaps go to +1.12, then down to +.81 and I'm going to have extra characters that are still being displayed.

In my stock app I'm displaying the initial results like this:

foreach (@test) { $_ =~ s/"//g; my (@color) = $change > 0 ? [ 0, 0, 255 ] : [ 255, 0, 0 ]; $main->AddLabel( -text => $arrow, -font => $arrow_font, -left => 55, -foreground => @color, -background => COLOR, -top => $h, ); # current security price $main->AddLabel( -text => pack( "A10", $current ), -font => $sec_font, -left => 70, -top => $h, -background => COLOR, ); # change in security price $main->AddLabel( -text => pack( "A10", $change ), -font => $sec_font, -left => 130, -top => $h, -background => COLOR, ); }

where test is a quote delimited string returned from Yahoo Finance. I'm not bothering with Text::CSV as it's never returning anything with an embedded apostrophe in it.

So when I want to update the information, I'm using the same technique but blank lines instead of the data that I'm scraping.

Is there a better way to go about displaying the data in one fell swoop that I've missed? If so, can someone point me to either the spot in the docs or some kind of tutorial?

Thanks in advance!

Revolution. Today, 3 O'Clock. Meet behind the monkey bars.

In reply to Refreshing text without flicker with AddLabel using Win32::GUI by Popcorn Dave

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.