ulis, 2006-01-10. Voici une fenêtre entièrement dynamique et construite avec grid. Le challenge est d'en faire autant avec pack ou place.
Pourquoi
Pour comparer les mérites respectifs des geometry managers.
Comment
En proposant un script qui construit une fenêtre relativement complexe et redimensionnable avec le geometry manager de son choix.
Greedings le challenger pour grid
# greedings
package require Tk
proc menuBar {menues} \
{
frame .menuBar -bg white
set col 0
foreach menu $menues \
{
label .menuBar.$col -text $menu -bg white
grid .menuBar.$col -row 0 -column $col -sticky w -padx 5 -pady 2
incr col
}
# fill the last col
grid columnconfigure .menuBar $col -weight 1
grid .menuBar -row 0 -column 0 -columnspan 2 -sticky ew
}
proc toolBar {tools} \
{
frame .toolBar -bd 1 -relief ridge
set col 0
foreach tool $tools \
{
button .toolBar.$col -text $tool -bd 1 -relief flat -over raised -pady 5
grid .toolBar.$col -row 0 -column $col -sticky w -padx 1 -pady 1
incr col
}
# fill the last col
grid columnconfigure .toolBar $col -weight 1
grid .toolBar -row 1 -column 0 -columnspan 2 -sticky ew
}
proc statusArea {areas} \
{
frame .statusArea -padx 10 -pady 4
canvas .statusArea.c -width 100 -height 0
grid .statusArea.c -row 0 -column 0
set row 0
foreach area $areas \
{
status $row $area
incr row
}
# fill the last row
grid rowconfigure .statusArea $row -weight 1
grid .statusArea -row 2 -column 0 -sticky n
}
proc displayArea {} \
{
frame .displayArea -bd 1 -relief groove -padx 4 -pady 4
text .displayArea.t -bd 0
scrollbar .displayArea.hs -orient horizontal
grid .displayArea.t -row 0 -column 0 -sticky nsew
grid .displayArea.hs -row 1 -column 0 -sticky sew
grid .displayArea -row 2 -column 1 -sticky nsew
grid rowconfigure .displayArea 0 -weight 1
grid columnconfigure .displayArea 0 -weight 1
}
proc statusBar {} \
{
frame .statusBar -bd 1 -relief sunken
label .statusBar.l
grid .statusBar.l -row 0 -column 0
grid .statusBar -row 3 -column 0 -columnspan 2 -sticky ew
}
proc status {row area} \
{
set color1 #606080
set color2 #8080c0
set color3 #d0d0c0
set a .statusArea.$row
foreach {action title} $area break
frame $a -padx 4 -pady 4 -bg $color1
frame $a.f1 -padx 5 -bg $color2 -pady 3
label $a.f1.l -text $title -anchor w -bg $color2 -padx 0 -pady 0
button $a.f1.b -width 2 -bg $color2 -bd 1 -highlightt 0 -padx 0 -pady 0
grid $a.f1.l -row 0 -column 0 -sticky ew
grid $a.f1.b -row 0 -column 1 -sticky e
grid columnconfigure $a.f1 0 -weigJL