Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Updating Tk while Tcl keeps running

36 views
Skip to first unread message

Cecil Westerhof

unread,
Dec 19, 2017, 1:28:05 PM12/19/17
to
I have the following code:
wm title . "Show CPU Temperature"
grid [ttk::label .temp -textvariable temp]
focus .temp
set temp [getCPUTemp]
# while {True} {
# set temp [getCPUTemp]
# puts [format "%s: %s" [clock format [clock seconds] -format %T] ${temp}]
# waitMinutes 1
# }

This displays my CPU temperature when the scripts starts, but does not
update it.
This would be done by the while loop, but then window is not
displayed. What need I to do to get this working?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Rich

unread,
Dec 19, 2017, 1:57:29 PM12/19/17
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> I have the following code:
> wm title . "Show CPU Temperature"
> grid [ttk::label .temp -textvariable temp]
> focus .temp
> set temp [getCPUTemp]
> # while {True} {
> # set temp [getCPUTemp]
> # puts [format "%s: %s" [clock format [clock seconds] -format %T] ${temp}]
> # waitMinutes 1
> # }
>
> This displays my CPU temperature when the scripts starts, but does not
> update it.
> This would be done by the while loop, but then window is not
> displayed. What need I to do to get this working?

How did you impliment "waitMinutes"?

What you will likely need to do is replace your 'while' loop with an
event loop instead. Tk only updates the display during idle time. A
while {true} {} loop never provides idle time for the background GUI
updates to happen.

Search the wiki for "How to keep a GUI alive" for more details.

Cecil Westerhof

unread,
Dec 19, 2017, 1:59:05 PM12/19/17
to
Cecil Westerhof <Ce...@decebal.nl> writes:

> I have the following code:
> wm title . "Show CPU Temperature"
> grid [ttk::label .temp -textvariable temp]
> focus .temp
> set temp [getCPUTemp]
> # while {True} {
> # set temp [getCPUTemp]
> # puts [format "%s: %s" [clock format [clock seconds] -format %T] ${temp}]
> # waitMinutes 1
> # }
>
> This displays my CPU temperature when the scripts starts, but does not
> update it.
> This would be done by the while loop, but then window is not
> displayed. What need I to do to get this working?

Answering my own question. ;-)

I did not understand things fully. What is needed:
wm title . "Show CPU Temperature"
grid [ttk::label .temp -textvariable temp]
updateCPUTemp

And the proc itself is then:
proc updateCPUTemp {} {
set ::temp [getCPUTemp]
puts [format "%s: %s" [clock format [clock seconds] -format %T] ${::temp}]
after [expr {(60 - ([clock seconds] % 60)) * 1000}] updateCPUTemp
}

Learning all the time.

Rich

unread,
Dec 19, 2017, 2:13:18 PM12/19/17
to
Yes, that runs your 'loop' via the Tk event loop. Allowing the
background updates to happen while your next 'after' event is pending.

Cecil Westerhof

unread,
Dec 19, 2017, 2:44:06 PM12/19/17
to
Rich <ri...@example.invalid> writes:

> Cecil Westerhof <Ce...@decebal.nl> wrote:
>> I have the following code:
>> wm title . "Show CPU Temperature"
>> grid [ttk::label .temp -textvariable temp]
>> focus .temp
>> set temp [getCPUTemp]
>> # while {True} {
>> # set temp [getCPUTemp]
>> # puts [format "%s: %s" [clock format [clock seconds] -format %T] ${temp}]
>> # waitMinutes 1
>> # }
>>
>> This displays my CPU temperature when the scripts starts, but does not
>> update it.
>> This would be done by the while loop, but then window is not
>> displayed. What need I to do to get this working?
>
> How did you impliment "waitMinutes"?

after miliseconds


> What you will likely need to do is replace your 'while' loop with an
> event loop instead. Tk only updates the display during idle time. A
> while {true} {} loop never provides idle time for the background GUI
> updates to happen.

Yeah, I found that. See my other post.


> Search the wiki for "How to keep a GUI alive" for more details.

Some interesting articles there.
0 new messages