All,
I have the following working example:
catch { destroy .w }
toplevel .w
canvas .w.cns -relief sunken -background "blue" -yscrollcommand ".w.cns.sbY set"
scrollbar .w.cns.sbY -orient vertical -command ".w.cns yview"
foreach id { 0 1 2 } {
if { 1 } {
frame .w.cns.frm$id
label .w.cns.frm$id.lbl -text "Label $id"
grid .w.cns.frm$id.lbl -row 0 -column 0
entry .w.cns.frm$id.ent -width 8
grid .w.cns.frm$id.ent -row 0 -column 1
} else {
checkbutton .w.cns.frm$id -text "CheckButton $id"
}
.w.cns create window 0 [expr { $id * 25 }] -window .w.cns.frm$id -anchor nw
}
pack .w.cns.sbY -side right
pack .w.cns -fill both
.w.cns configure -scrollregion [.w.cns bbox all]
It's rough looking, but if you look in the canvas box, you'll notice that you can only scroll two thirds of the way down - not all the way down (there are 3 rows of widgets)!
Diagnosing things, I noticed that the canvas' "bbox all" is returning the wrong value. It is returning 1 pixel greater than the y value I use in "create window". If, after executing the above code, I manually call ".w.cns configure -scrollregion [.w.cns bbox all]", "bbox all" returns the correct value and I can scroll through all 3 rows of widgets. I also noticed I can add an "update" call right before the configure call to get it working. Unfortunately, I don't see these as good solutions (discussed more later).
I think I understand the problem here. The label/entry/checkbox is not getting built until after the configure happens when we return to the main messaging loop. This is why the second configure call works when I type it in the console.
"update", on the other hand, forces the messaging loop to be called recursively, which fixes the problem as well. update causes the label/entry/checkbox to be full built and "bbox all" returns the right value. However, update also causes all sorts of problems because I sometimes get the rug pulled out from under me (one example is if the user is quick enough to close the dialog box before update gets hit - not possible in this example, but a problem I have seen in other code misusing update).
Is there a hook I can use for the above example? I know <Configure> will work on building the first time - problem is, that doesn't solve the problem when I want to add something on the fly. Here is some example code:
set id 3
checkbutton .w.cns.frm$id -text "CheckButton $id"
.w.cns create window 0 [expr { $id * 25 }] -window .w.cns.frm$id -anchor nw
.w.cns configure -scrollregion [.w.cns bbox all]
What hook can I use that I can trust in each case? By the way, Configure in my opinion is slightly overkill for this task, since it'll get called many more times than necessary.
Also, is there a better recommended widget? This is a secondary question, since I have no choice but to use canvas for now.
Thanks for any help!
I have the following working example:
catch { destroy .w }
toplevel .w
canvas .w.cns -relief sunken -background "blue" -yscrollcommand ".w.cns.sbY set"
scrollbar .w.cns.sbY -orient vertical -command ".w.cns yview"
foreach id { 0 1 2 } {
if { 1 } {
frame .w.cns.frm$id
label .w.cns.frm$id.lbl -text "Label $id"
grid .w.cns.frm$id.lbl -row 0 -column 0
entry .w.cns.frm$id.ent -width 8
grid .w.cns.frm$id.ent -row 0 -column 1
} else {
checkbutton .w.cns.frm$id -text "CheckButton $id"
}
.w.cns create window 0 [expr { $id * 25 }] -window .w.cns.frm$id -anchor nw
}
pack .w.cns.sbY -side right
pack .w.cns -fill both
.w.cns configure -scrollregion [.w.cns bbox all]
It's rough looking, but if you look in the canvas box, you'll notice that you can only scroll two thirds of the way down - not all the way down (there are 3 rows of widgets)!
Diagnosing things, I noticed that the canvas' "bbox all" is returning the wrong value. It is returning 1 pixel greater than the y value I use in "create window". If, after executing the above code, I manually call ".w.cns configure -scrollregion [.w.cns bbox all]", "bbox all" returns the correct value and I can scroll through all 3 rows of widgets. I also noticed I can add an "update" call right before the configure call to get it working. Unfortunately, I don't see these as good solutions (discussed more later).
I think I understand the problem here. The label/entry/checkbox is not getting built until after the configure happens when we return to the main messaging loop. This is why the second configure call works when I type it in the console.
"update", on the other hand, forces the messaging loop to be called recursively, which fixes the problem as well. update causes the label/entry/checkbox to be full built and "bbox all" returns the right value. However, update also causes all sorts of problems because I sometimes get the rug pulled out from under me (one example is if the user is quick enough to close the dialog box before update gets hit - not possible in this example, but a problem I have seen in other code misusing update).
Is there a hook I can use for the above example? I know <Configure> will work on building the first time - problem is, that doesn't solve the problem when I want to add something on the fly. Here is some example code:
set id 3
checkbutton .w.cns.frm$id -text "CheckButton $id"
.w.cns create window 0 [expr { $id * 25 }] -window .w.cns.frm$id -anchor nw
.w.cns configure -scrollregion [.w.cns bbox all]
What hook can I use that I can trust in each case? By the way, Configure in my opinion is slightly overkill for this task, since it'll get called many more times than necessary.
Also, is there a better recommended widget? This is a secondary question, since I have no choice but to use canvas for now.
Thanks for any help!