LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-10-2005, 11:07 AM   #1
Atrocity
Member
 
Registered: Nov 2002
Location: Hell
Distribution: FreeBSD, Slackware
Posts: 308

Rep: Reputation: 30
PerlTK loose control in loop


I have been trying to make a timer in perl for my TK gui to update information as it changes. I did try some code with Sig Alarm but it doesnt work when you are idle so I came up with this.

#! usr/bin/perl
use Tk;

Lots of fun GUI stuff here


for ( ; ; ) {

code that needs to work every 3 seconds


for ($i=0; $i<30000000; $i++) { #takes about 3 seconds

}

}



MainLoop; #end of TK loop



This does do the comands every 3 seconds but control of the gui is completly gone and it just keeps processing the info every 3 seconds but doesnt display becuase GUI has lost control..

Note: Added the timer in a sub routine thats called by a button becuase if I dont do that the GUI will not even load up it will process the loop forever since it is infinate and never make a gui!!!

I am new to perl and do not know whats wrong, Does anyone got any ideas or suggestions to fix this problem or a better way to do it????????

Thanx in advance

Last edited by Atrocity; 05-10-2005 at 11:09 AM.
 
Old 05-10-2005, 12:16 PM   #2
Atrocity
Member
 
Registered: Nov 2002
Location: Hell
Distribution: FreeBSD, Slackware
Posts: 308

Original Poster
Rep: Reputation: 30
Haha after a week of searching I post in here and figure it out 10 min later, thats how retarted I am. anyway I will post what I did to make it work for all the other kids with the same problems here it goes enjoy

You can use a tk method called after

#! usr/bin/perl
use Tk;

$mw=new MainWindow;


Lots of fun GUI stuff here


my $id = Tk::After->new($mw,5000,'repeat',\&refresh); # takes the mainwindow and refreshes it every 5000 #miliseconds or somthing at which time it goes to the refresh subroutine and does its thing.........


MainLoop; #end of TK loop


sub refresh{

code that needs to work every few seconds

}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newb on the loose and needing help Cobra08t Linux - Newbie 4 07-14-2005 12:54 PM
PerlTk package juris Mandriva 0 10-26-2004 04:36 AM
set perlTK always-on-top \ topmost plast1cfl00r Programming 0 08-21-2004 02:24 PM
aterm loose the borders Longinus Linux - Software 10 03-25-2004 11:41 PM
There is a Guru on the loose! MasterC General 6 01-30-2003 12:49 AM


All times are GMT -5. The time now is 01:59 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration