From: Why Tea on
Got this from TclTk Wiki for a poor man's progress bar:

canvas .c -width 200 -height 20 -bd 1 -relief groove -highlightt 0
.c create rectangle 0 0 0 20 -tags bar -fill navy
pack .c -padx 10 -pady 10
# run
focus -force .c
raise .c
for {set i 0} {$i < 100} {incr i} \
{
.c coords bar 0 0 [expr {int($i * 2)}] 20
after 100
update
}

It works fine as a standalone TK script, but not when turned into a
proc like below.
proc progressbar {} {
canvas .c -width 200 -height 20 -bd 1 -relief groove -highlightt 0
.c create rectangle 0 0 0 20 -tags bar -fill navy
pack .c -padx 10 -pady 10
# run
focus -force .c
raise .c
for {set i 0} {$i < 100} {incr i} \
{
.c coords bar 0 0 [expr {int($i * 2)}] 20
after 100
update
}
}

....
button $w.ok -text OK -width 8 -command { progressbar } # nothing
happens!!!
....

Where did I go wrong?

/Why Tea
From: Arndt Roger Schneider on
Why Tea schrieb:

>Got this from TclTk Wiki for a poor man's progress bar:
>
> canvas .c -width 200 -height 20 -bd 1 -relief groove -highlightt 0
> .c create rectangle 0 0 0 20 -tags bar -fill navy
> pack .c -padx 10 -pady 10
> # run
> focus -force .c
> raise .c
> for {set i 0} {$i < 100} {incr i} \
> {
> .c coords bar 0 0 [expr {int($i * 2)}] 20
> after 100
> update
> }
>
>It works fine as a standalone TK script, but not when turned into a
>proc like below.
>proc progressbar {} {
> canvas .c -width 200 -height 20 -bd 1 -relief groove -highlightt 0
> .c create rectangle 0 0 0 20 -tags bar -fill navy
> pack .c -padx 10 -pady 10
> # run
> focus -force .c
> raise .c
> for {set i 0} {$i < 100} {incr i} \
> {
> .c coords bar 0 0 [expr {int($i * 2)}] 20
> after 100
> update
> }
>}
>
>...
>button $w.ok -text OK -width 8 -command { progressbar } # nothing
>happens!!!
>...
>
>
>
button .ok -text OK -width 8 -command { progressbar }
pack .ok

# Hit the OK-Button.


>Where did I go wrong?
>
>/Why Tea
>
>
From: Why Tea on
On May 3, 10:27 pm, Arndt Roger Schneider <arndt.ro...(a)web.de> wrote:
> Why Tea schrieb:
>
>
>
> >Got this from TclTk Wiki for a poor man's progress bar:
>
> >  canvas .c -width 200 -height 20 -bd 1 -relief groove -highlightt 0
> >  .c create rectangle 0 0 0 20 -tags bar -fill navy
> >  pack .c -padx 10 -pady 10
> >  # run
> >  focus -force .c
> >  raise .c
> >  for {set i 0} {$i < 100} {incr i} \
> >  {
> >    .c coords bar 0 0 [expr {int($i * 2)}] 20
> >    after 100
> >    update
> >  }
>
> >It works fine as a standalone TK script, but not when turned into a
> >proc like below.
> >proc progressbar {} {
> >  canvas .c -width 200 -height 20 -bd 1 -relief groove -highlightt 0
> >  .c create rectangle 0 0 0 20 -tags bar -fill navy
> >  pack .c -padx 10 -pady 10
> >  # run
> >  focus -force .c
> >  raise .c
> >  for {set i 0} {$i < 100} {incr i} \
> >  {
> >    .c coords bar 0 0 [expr {int($i * 2)}] 20
> >    after 100
> >    update
> >  }
> >}
>
> >...
> >button $w.ok -text OK -width 8 -command { progressbar }   # nothing
> >happens!!!
> >...
>
> button .ok  -text OK -width 8 -command { progressbar }
> pack .ok
>
> # Hit the OK-Button.
>
> >Where did I go wrong?
>
> >/Why Tea
>
>

That works. Thanks. But I tried to use Grid from
another Wiki example and it failed to work.
From: Larry W. Virden on
On May 3, 8:48 am, Why Tea <ytl...(a)gmail.com> wrote:

>
> That works. Thanks. But I tried to use Grid from
> another Wiki example and it failed to work

I seem to recall warnings about mixing Grid and pack (or, for that
matter, perhaps any 2 or more geometry managers) within a particular
widget, due to race conditions ...
From: Arndt Roger Schneider on
Why Tea schrieb:

>On May 3, 10:27 pm, Arndt Roger Schneider <arndt.ro...(a)web.de> wrote:
>
>
>>Why Tea schrieb:
>>
>>
>>
>>
>>
>>>Got this from TclTk Wiki for a poor man's progress bar:
>>>
>>>
>>> canvas .c -width 200 -height 20 -bd 1 -relief groove -highlightt 0
>>> .c create rectangle 0 0 0 20 -tags bar -fill navy
>>> pack .c -padx 10 -pady 10
>>> # run
>>> focus -force .c
>>> raise .c
>>> for {set i 0} {$i < 100} {incr i} \
>>> {
>>> .c coords bar 0 0 [expr {int($i * 2)}] 20
>>> after 100
>>> update
>>> }
>>>
>>>
>>>It works fine as a standalone TK script, but not when turned into a
>>>proc like below.
>>>proc progressbar {} {
>>> canvas .c -width 200 -height 20 -bd 1 -relief groove -highlightt 0
>>> .c create rectangle 0 0 0 20 -tags bar -fill navy
>>> pack .c -padx 10 -pady 10
>>> # run
>>> focus -force .c
>>> raise .c
>>> for {set i 0} {$i < 100} {incr i} \
>>> {
>>> .c coords bar 0 0 [expr {int($i * 2)}] 20
>>> after 100
>>> update
>>> }
>>>}
>>>
>>>
>>>...
>>>button $w.ok -text OK -width 8 -command { progressbar } # nothing
>>>happens!!!
>>>...
>>>
>>>
>>button .ok -text OK -width 8 -command { progressbar }
>>pack .ok
>>
>># Hit the OK-Button.
>>
>>
>>
>>>Where did I go wrong?
>>>
>>>
>>>/Why Tea
>>>
>>>
>>
>>
>
>That works. Thanks. But I tried to use Grid from
>another Wiki example and it failed to work.
>
>



As Larry pointed out: mixing two geometry managers inside the same region
is potential dangerous.

To be exact: Mixing two propagating geometry managers in the same region
will end in a feedback-loop:



label .l -text mylabel

button .l.b -text feedback
pack .l.b -in .l -padx 12 -pady 12
pack .l

## Feedback-loop


label .l -text "pack grid"
button .b -text "grid pack feedback"
pack .l
grid .b -column 0 -row 0

## Feedback-loop






# turn propagation off for region . and pack:
pack propagate . 0
pack [label .l "propagate turned off for pack"
grid [button .b -text "grid propagates its size"] -column 0 -row 0

# OK, only grid uses propagation inside "."


However, there is no conceivable use-case for mixing grid and pack inside
the same region.

Back to your proressbar:
You know that you should destroy the canvas ".c" inside proc progressbar?

-roger