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

Re: Antw: Re: Perl/Tk + Thread

Thread Previous | Thread Next
May 24, 2003 06:24
Re: Antw: Re: Perl/Tk + Thread
Message ID:
On Tue, 20 May 2003 08:11:13 +0200, (Jaschar Otto)

>>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.
>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:

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

>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

>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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About