Hello Monks,

I have one problem.

I was did a program to be a interface between a chat to desktop, to send and received messages but out of browser.

It's okay to received or send messages if the routines are separate in two programs, but to join both on a one program need some mechanism to manipulate both routines, because the shell (on Windows or Linux) can't receive and send in same time.

To do it I make an interface with Tk, but to receive message have some problem, when Tk make a Loop it receive only one message, to receive next I need to kill just a interface, or restart the program.

In fact, I really didn't know to use the Tk, I'm trying to two weeks but I could not, if someone can help me.

Here's the code:

#!usr/bin/env perl use Tk; use common::sense; use WWW::Mechanize; use WWW::Mechanize::DecodedContent; use JSON -support_by_pp; use HTTP::Cookies; use URI::Escape; my $mw = new MainWindow(-background => 'blue'); $mw->geometry("600x400"); $mw->minsize(qw(400 650)); $mw->maxsize(qw(800 750)); $mw->title("Invaders External ShoutBox"); my $getmsg = $mw -> Frame(-background => 'red', -relief=>'raised', -borderwidth=>1, ) ->place(-x =>70, -y =>25); my $gmsg = $getmsg->Scrolled ('Text', -width=> 60, -height => 20, -background => 'black', -foreg +round => 'green')->pack; $gmsg->insert('end',"Start External ShoutBox...\nInVaDeRs\n"); my $putmsg = $mw -> Frame(-background => 'red', -relief=>'raised', -borderwidth=>1, ) ->place(-x => 70, -y => 450); my $pmsg = $putmsg->Scrolled ('Text', -width=> 60, -height => 5, -background => 'black', -foregr +ound => 'green')->pack; $pmsg->insert('end',"..."); my $url = WWW::Mechanize->new(); $url->get("http://www.forum-invaders.com.br/vb/login.php"); $url->submit_form( fields => { vb_login_username => 'login', vb_login_password => 'password', } ); if($url->decoded_content !~ /Bem-vindo/gi){$gmsg->insert('end', "L +oggin Error\n");} else {$gmsg->insert('end', "Login OK!\n");} my $work = 1; my @old; my $num = 0; while ($work == 1){ my $r = $url->get("http://www.forum-invaders.com.br/vb/vbshout +.php?type=activeusers&do=ajax&action=fetch&instanceid=2"); my $json = JSON->new->relaxed; my $s = $json->decode($r->decoded_content); my $msg = $s->{"shouts"}->{0}->{"message_raw"}; my $user = $s->{"shouts"}->{0}->{"musername"}; my $name; if ($user =~ />(.+)<\/span/gi) {$name = $1;} else {$name = $user} my $now = join(" => ", $name, $msg) . "\n"; if ($num == 0){ $gmsg->insert('end', $now); push (@old, $now); $num++; } elsif($old[$num - 1] ne $now){ $gmsg->insert('end', $now); push (@old, $now); $num++; } } MainLoop;

In reply to [HELP] Chat, two routines, Tk by acpguedes

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.