develooper Front page | perl.beginners | Postings from May 2003

Re: Antw: Re: Perl/Tk + Thread

Thread Previous | Thread Next
From:
zentara
Date:
May 24, 2003 06:24
Subject:
Re: Antw: Re: Perl/Tk + Thread
Message ID:
i7sucvcobd94g8tpoftcqo03246knjdvtv@4ax.com
On Tue, 20 May 2003 08:11:13 +0200, Jaschar.Otto@shz.de (Jaschar Otto)
wrote:

>>You were alamost there, here is 1 way. The mouse needs to be over the
>>counter box, for the "exit on keypress to work.  Also, "thread" dosn't
>>mean what you think in this Tk example. This is just a main window being
>>updated, it is not threaded.
>
>$mw->repeat(1,\&update);
>
>sub update {
>         $variable += 1;
>         $label->update; 
>	 sleep(1);
> }
>
>i experimented and this doesn't work like i wanted it,
>the tk window suddenly behaved wierd and didn't react
>sometimes, apparently because of the 'sleep(1)'.
>i tried around and found this solution:
>
>$mw->repeat(1000,\&update);

Yeah, you are right, I was just guessing at the meaning and
was wrong. The first entry in the arguments for repeat() is
the ms delay not count. Read about it in "perldoc Tk::after".
It works fine though for me with Perl5.8 and linux. 
So 1000 gives you a 1 second delay. So you won't need the
sleep(1).

>
>sub update {
>         $variable += 1;
>         $label->update; 
> }
>
>the $label->update; doesn't seem to be neccessary, too,
>is there any special reason why you used it ? I'm a perl/tk
>noob and don't know if there could be problems if i don't
>use it.

Well in this case, it seems that the main window is being automatically
updated everytime repeat is called; however generally in Tk you have to
tell it when to update the widgets with new values.  So you are right
again, but remember, generally widgets won't change until you tell them
to.

>
>thanks for your help anyways, i didn't know the repeat command before.
perldoc Tk::after

Yeah, I could try and cover up my bad example by saying I was trying to
get you thinking, but I was just lazy. I whipped up something that
worked for me, and posted it. Bad, bad.

Anyways, you have to admit that you will remember better since you had
to fix the code yourself. :-)



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About