clock.tcl

# clock.tcl
 proc every {ms body} {
    eval $body
    after $ms [list every $ms $body]
 }
 pack [label .l -textvar time -font {Tahoma 24}]
 pack [button .b -text X -command exit]
 every 1000 {set ::time [clock format [clock sec] -format %H:%M:%S]}

LV It probably would be best for whoever added the above to add a name and a EULA type statement indicating the code is allowed to be reused. - RS: I put it here in order to test whether pages with .tcl titles are still delivered as plain text (they aren't), and trying to have my XDA execute it somehow - but it didn't work :( And re licensing: doesn't Who owns the content on this Wiki tell it clearly enough?

Well, it certainly sets a general expectation. However, applications having the licensing spelled out explicitly ensures there is no confusion when the application is reaped from the wiki into a distribution.


EKB I took this and expanded it into a Task Timer. It lacks the elegant simplicity of the code above, but it adds some functionality that I was looking for. I've actually ended up using it a lot for keeping track of my billed time.


escargo 19 Jul 2005 - Here is a variation that I created so that the time would show even if the application was reduced to the Windows Taskbar. However, there is some behavior that I found quite curious. So, here is a slight change from the original code, primarily to set the time into the applications title and the iconname.

 proc every {ms body} {
    eval $body
    after $ms [list every $ms $body]
 }
 
 proc update {} {
     set ::time [clock format [clock sec] -format %H:%M:%S]
     wm title . $::time
     wm iconname . $::time
 }
 
 
 pack [label .l -textvar time -font {Tahoma 24}]
 pack [button .b -text Exit -command exit]
 every 1000 {update}

Now, here is the curious behavior. If this app is run (on Windows XP Pro with ActiveTcl 8.4.9), if the app is minimized so that it's on the task bar, the timer updates. (It's only advantage over the taskbar clock is that it counts the seconds.) But if there are two Tcl apps running at the same time, the taskbar shows "2 Wish Application" (because of stacking of the two apps because the taskbar is full). If you click on the taskbar icon for the two apps the iconnames show but the iconnames don't update! Even more amusing is that the iconnames appear in tooltips when you roll over the iconnames with the updated values that are not shown in the iconnames. It's not clear what the expected behavior ought to be; I thought that the iconnames should update just as well when the iconnames are stacked as when they are sitting on the taskbar, but apparently some graphical update threads are not being called when they are stacked.