Grupos de Google ya no admite publicaciones ni suscripciones nuevas de Usenet. El contenido anterior sigue visible.

Updating Tk while Tcl keeps running

36 vistas
Ir al primer mensaje no leído

Cecil Westerhof

no leída,
19 dic 2017, 1:28:05 p.m.19/12/2017
para
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

no leída,
19 dic 2017, 1:57:29 p.m.19/12/2017
para
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

no leída,
19 dic 2017, 1:59:05 p.m.19/12/2017
para
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

no leída,
19 dic 2017, 2:13:18 p.m.19/12/2017
para
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

no leída,
19 dic 2017, 2:44:06 p.m.19/12/2017
para
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 mensajes nuevos