From: Why Tea on 3 May 2010 07:20 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 3 May 2010 08:27 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 3 May 2010 08:48 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 3 May 2010 15:04 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 3 May 2010 16:39 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
|
Pages: 1 Prev: Tk and interp questions Next: png images coming up very slow on Windows7 |