G'day Special_K,

Unfortunately, you're completely on the wrong track with an infinite loop constantly checking for a status change. A change of status, however that is effected, is an event: you should allow Tk to respond to such an event.

I don't think popping up a window for the notification is the right way to go. You could perhaps use a Tk::Toplevel that holds the notification. That's going to be messy. If it obscures part of the main GUI, user intervention will be needed to move it or bring the main GUI back to the foreground. Then there's the question of how long the popup persists. You could use Tk::after to remove it automatically after a certain period of time: that needs to be long enough for the user to read it; but not so long that you that get a number of popups all piled on top of each other.

I would implement what you're trying to do with a status bar that notifies individual changes, some sort of window with a log of status changes as they occur, or perhaps even both. I've put together a short script to demonstrate both methods; changing the selected radiobutton simulates a status change.

#!/usr/bin/env perl use strict; use warnings; use Tk; my $mw = MainWindow::->new(-title => 'Status Notifications'); $mw->geometry('512x288+50+100'); my $status = 'A'; my $last_status = $status; my $status_msg; _set_status_msg($status, \$status_msg); my $status_bar_F = $mw->Frame( )->pack(-side => 'bottom', -fill => 'x'); $status_bar_F->Label( -textvariable => \$status_msg, -anchor => 'w', -relief => 'sunken', )->pack(-fill => 'x'); my $main_F = $mw->Frame( )->pack(-side => 'top', -fill => 'both', -expand => 1); my $text_F = $main_F->Frame( )->pack(-side => 'right', -fill => 'y'); my $status_text = $text_F->Text( -width => 50, )->pack(); $status_text->insert(end => "$status_msg\n"); my $radio_F = $main_F->Frame( )->pack(-side => 'left', -fill => 'both', -expand => 1); for my $status_letter ('A' .. 'F') { $radio_F->Radiobutton( -text => $status_letter, -variable => \$status, -value => $status_letter, -command => sub { if ($status ne $last_status) { $last_status = $status; _set_status_msg($status_letter, \$status_msg); $status_text->insert(end => "$status_msg\n"); } }, )->pack(-side => 'top', -anchor => 'w', -pady => 2); } MainLoop; sub _set_status_msg { my ($status, $msg_ref) = @_; $$msg_ref = 'Status: ' . $status . '; Changed at: ' . localtime(); return; }

That code is fully functional and should work as is. Pay particular attention to references; for example, \$status_msg, \$status, and $$msg_ref in various places.

— Ken


In reply to Re: How to display Tk window without waiting for user input by kcott
in thread How to display Tk window without waiting for user input by Special_K

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.