Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

implementing a Timer

Status
Not open for further replies.

kansasjayhawk

Programmer
Aug 15, 2001
1
0
0
GB
I am building a simple GUI with Tcl/Tk, part of which is recording data to a file. As the file grows, I want to display its size, refreshed maybe every second or two. If I write a very simple loop that does this, all other pointer events on the GUI don't respond. If I update idle tasks at the end of this loop, they at least respond every time that line is reached. I think I need a timer to insert
Code:
 .fileSizelbl configure -text [file size data.dat]
every two seconds into the list of events being processed. Or somehow concurrently respond to events on the GUI and refresh this file size. I've considered creating another interpreter, but it would still need to access the original GUI, and I'm back to the same problem of updating it. This seems fundamental, but I can't seem to solve it.
 
Try the after command

after 2000 {.fileSizelbl configure -text [file size data.dat]}

This should keep the GUI active. Time units are milliseconds.

In order to do this every 2 seconds forever, you'll need a proc that calls itself using after - something like this:

proc file_size_update { } {
.fileSizelbl configure -text [file size data.dat]
after 2000 {file_size_update}
}

To start it, call file_size_update once from the main part of your program. To shut it off, use after cancel.

This behaves like recursion, but it's really not. If you were to recurse, eventually you'd get a message like "too many levels of recursion" or something like that.

Good luck,

Jeff Dinsmore
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top