Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How to display Tk window without waiting for user input

by tybalt89 (Prior)
on Jan 16, 2021 at 20:31 UTC ( #11127011=note: print w/replies, xml ) Need Help??


in reply to How to display Tk window without waiting for user input

Here's an example that uses a Toplevel to fake a messagebox, and ->after for the timing.
Fill in the toplevel with whatever message you want. I sort of tried to simulate what you say you want to do.
If the scraper is a long running process, take a look at Tk::IO which would run it in a sub-process and just fetch the results.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11126974 use warnings; use Tk; my $fakebox; my $oldstatus = ''; my $vertical = 0; my $mw = MainWindow->new; $mw->geometry( '+500+600' ); $mw->Button( -text => 'Exit', -command => sub {$mw->destroy}, -font => 'courierbold 24')->pack; $mw->after( 1, \&checker ); MainLoop; sub checker { my $new = localtime(); # replace localtime with your scraper results if( $new ne $oldstatus ) { $fakebox and $fakebox->destroy; $fakebox = $mw->Toplevel(); $fakebox->title( 'Message Box' ); # really fake it :) $fakebox->geometry( '+300+' . (300, 400)[$vertical ^= 1] ); $fakebox->Label( -text => ' Notice ', -font => 'times 24', -fg => 'white', -bg => 'red3' )->pack; $fakebox->Label( -text => $new, -font => 'times 24' )->pack; $oldstatus = $new; } $mw->after( 3000, \&checker ); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11127011]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2021-02-28 20:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?