📄 grid.test
字号:
grid .f grid rowconfigure . 0 -weight 1 grid columnconfigure . 0 -weight 1 grid propagate . 0 . configure -width 250 -height 150 foreach i { {} n s e w ns ew nw ne se sw nse nsw sew new nsew} { grid .f -sticky $i update array set data [grid info .f] append a "($data(-sticky)) [winfo x .f] [winfo y .f] [winfo width .f] [winfo height .f]\n" } set a} {() 25 25 200 100(n) 25 0 200 100(s) 25 50 200 100(e) 50 25 200 100(w) 0 25 200 100(ns) 25 0 200 150(ew) 0 25 250 100(nw) 0 0 200 100(ne) 50 0 200 100(es) 50 50 200 100(sw) 0 50 200 100(nes) 50 0 200 150(nsw) 0 0 200 150(esw) 0 50 250 100(new) 0 0 250 100(nesw) 0 0 250 150}grid_reset 12.1 test grid-12.2 {-sticky} { frame .f -bg red list [catch "grid .f -sticky glue" msg] $msg} {1 {bad stickyness value "glue": must be a string containing n, e, s, and/or w}}grid_reset 12.2 test grid-12.3 {-sticky} { frame .f -bg red grid .f -sticky {n,s,e,w} array set A [grid info .f] set A(-sticky)} {nesw}grid_reset 12.3test grid-13.1 {-in} { frame .f -bg red list [catch "grid .f -in .f" msg] $msg} {1 {Window can't be managed in itself}}grid_reset 13.1test grid-13.2 {-in} { frame .f -bg red list [catch "grid .f -in .bad" msg] $msg} {1 {bad window path name ".bad"}}grid_reset 13.2test grid-13.3 {-in} { frame .f -bg red toplevel .top list [catch "grid .f -in .top" msg] $msg} {1 {can't put .f inside .top}}destroy .topgrid_reset 13.3test grid-13.4 {-ipadx} { frame .f -width 20 -height 20 -highlightthickness 0 -bg red list [catch "grid .f -ipadx x" msg] $msg} {1 {bad ipadx value "x": must be positive screen distance}}grid_reset 13.4test grid-13.5 {-ipadx} { frame .f -width 200 -height 100 -highlightthickness 0 -bg red grid .f update set a [winfo width .f] grid .f -ipadx 1 update list $a [winfo width .f]} {200 202}grid_reset 13.5test grid-13.6 {-ipady} { frame .f -width 20 -height 20 -highlightthickness 0 -bg red list [catch "grid .f -ipady x" msg] $msg} {1 {bad ipady value "x": must be positive screen distance}}grid_reset 13.6test grid-13.7 {-ipady} { frame .f -width 200 -height 100 -highlightthickness 0 -bg red grid .f update set a [winfo height .f] grid .f -ipady 1 update list $a [winfo height .f]} {100 102}grid_reset 13.7test grid-13.8 {-padx} { frame .f -width 20 -height 20 -highlightthickness 0 -bg red list [catch "grid .f -padx x" msg] $msg} {1 {bad padx value "x": must be positive screen distance}}grid_reset 13.8test grid-13.9 {-padx} { frame .f -width 200 -height 100 -highlightthickness 0 -bg red grid .f update set a "[winfo width .f] [winfo width .]" grid .f -padx 1 update list $a "[winfo width .f] [winfo width .]"} {{200 200} {200 202}}grid_reset 13.9test grid-13.10 {-pady} { frame .f -width 20 -height 20 -highlightthickness 0 -bg red list [catch "grid .f -pady x" msg] $msg} {1 {bad pady value "x": must be positive screen distance}}grid_reset 13.10test grid-13.11 {-pady} { frame .f -width 200 -height 100 -highlightthickness 0 -bg red grid .f update set a "[winfo height .f] [winfo height .]" grid .f -pady 1 update list $a "[winfo height .f] [winfo height .]"} {{100 100} {100 102}}grid_reset 13.11test grid-13.12 {-ipad x and y} { frame .f -width 20 -height 20 -highlightthickness 0 -bg red grid columnconfigure . 0 -minsize 150 grid rowconfigure . 0 -minsize 100 set a "" foreach x {0 5} { foreach y {0 5} { grid .f -ipadx $x -ipady $y update append a " $x,$y:" foreach prop {x y width height} { append a ,[winfo $prop .f] } } } set a} { 0,0:,65,40,20,20 0,5:,65,35,20,30 5,0:,60,40,30,20 5,5:,60,35,30,30}grid_reset 13.12test grid-13.13 {reparenting} { frame .1 frame .2 button .b grid .1 .2 grid .b -in .1 set a "" catch {unset info}; array set info [grid info .b] lappend a [grid slaves .1],[grid slaves .2],$info(-in) grid .b -in .2 catch {unset info}; array set info [grid info .b] lappend a [grid slaves .1],[grid slaves .2],$info(-in) unset info set a} {.b,,.1 ,.b,.2}grid_reset 13.13test grid-14.1 {structure notify} { frame .f -width 200 -height 100 -highlightthickness 0 -bg red frame .g -width 200 -height 100 -highlightthickness 0 -bg red grid .f grid .g -in .f update set a "" lappend a "[winfo x .g],[winfo y .g] \ [winfo width .g],[winfo height .g]" .f configure -bd 5 -relief raised update lappend a "[winfo x .g],[winfo y .g] \ [winfo width .g],[winfo height .g]" set a} {{0,0 200,100} {5,5 200,100}}grid_reset 14.1test grid-14.2 {structure notify} { frame .f -width 200 -height 100 frame .f.g -width 200 -height 100 grid .f grid .f.g update set a "" lappend a [grid bbox .],[grid bbox .f] .f config -bd 20 update lappend a [grid bbox .],[grid bbox .f]} {{0 0 200 100,0 0 200 100} {0 0 240 140,20 20 200 100}}grid_reset 14.2test grid-14.3 {map notify} { global A catch {unset A} bind . <Configure> {incr A(%W)} set A(.) 0 foreach i {0 1 2} { frame .$i -width 100 -height 75 set A(.$i) 0 } grid .0 .1 .2 update bind <Configure> .1 {destroy .0} .2 configure -bd 10 update bind . <Configure> {} array get A} {.2 2 .0 1 . 1 .1 1}grid_reset 14.3test grid-15.1 {lost slave} { button .b grid .b set a [grid slaves .] pack .b lappend a [grid slaves .] grid .b lappend a [grid slaves .]} {.b {} .b}grid_reset 15.1test grid-15.2 {lost slave} { frame .f grid .f button .b grid .b -in .f set a [grid slaves .f] pack .b lappend a [grid slaves .f] grid .b -in .f lappend a [grid slaves .f]} {.b {} .b}grid_reset 15.2test grid-16.1 {layout centering} { foreach i {0 1 2} { frame .$i -bg gray -width 75 -height 50 -bd 2 -relief ridge grid .$i -row $i -column $i -sticky nswe } grid propagate . 0 . configure -width 300 -height 250 update grid bbox .} {37 50 225 150}grid_reset 16.1test grid-16.2 {layout weights (expanding)} { foreach i {0 1 2} { frame .$i -bg gray -width 75 -height 50 -bd 2 -relief ridge grid .$i -row $i -column $i -sticky nswe grid rowconfigure . $i -weight [expr $i + 1] grid columnconfigure . $i -weight [expr $i + 1] } grid propagate . 0 . configure -width 500 -height 300 set a "" update foreach i {0 1 2} { lappend a [winfo width .$i]-[winfo height .$i] } set a} {120-75 167-100 213-125}grid_reset 16.2test grid-16.3 {layout weights (shrinking)} { foreach i {0 1 2} { frame .$i -bg gray -width 100 -height 75 -bd 2 -relief ridge grid .$i -row $i -column $i -sticky nswe grid rowconfigure . $i -weight [expr $i + 1] grid columnconfigure . $i -weight [expr $i + 1] } grid propagate . 0 . configure -width 200 -height 150 set a "" update foreach i {0 1 2} { lappend a [winfo width .$i]-[winfo height .$i] } set a} {84-63 66-50 50-37}grid_reset 16.3test grid-16.4 {layout weights (shrinking with minsize)} { foreach i {0 1 2} { frame .$i -bg gray -width 100 -height 75 -bd 2 -relief ridge grid .$i -row $i -column $i -sticky nswe grid rowconfigure . $i -weight [expr $i + 1] -minsize 45 grid columnconfigure . $i -weight [expr $i + 1] -minsize 65 } grid propagate . 0 . configure -width 200 -height 150 set a "" update foreach i {0 1 2} { lappend a [winfo width .$i]-[winfo height .$i] } set a} {70-60 65-45 65-45}grid_reset 16.4test grid-16.5 {layout weights (shrinking at minsize)} { foreach i {0 1 2} { frame .$i -bg gray -width 100 -height 75 -bd 2 -relief ridge grid .$i -row $i -column $i -sticky nswe grid rowconfigure . $i -weight 0 -minsize 70 grid columnconfigure . $i -weight 0 -minsize 90 } grid propagate . 0 . configure -width 100 -height 75 set a "" update foreach i {0 1 2} { lappend a [winfo width .$i]-[winfo height .$i] } set a} {100-75 100-75 100-75}grid_reset 16.5test grid-16.6 {layout weights (shrinking at minsize)} { foreach i {0 1 2} { frame .$i -bg gray -width 100 -height 75 -bd 2 -relief ridge grid .$i -row $i -column $i -sticky nswe grid rowconfigure . $i -weight [expr $i + 1] -minsize 52 grid columnconfigure . $i -weight [expr $i + 1] -minsize 69 } grid propagate . 0 . configure -width 200 -height 150 set a "" update foreach i {0 1 2} { lappend a [winfo width .$i]-[winfo height .$i] } set a} {69-52 69-52 69-52}grid_reset 16.6test grid-16.7 {layout weights (shrinking at minsize)} { foreach i {0 1 2} { frame .$i -bg gray -width 100 -height 75 -bd 2 -relief ridge grid .$i -row $i -column $i -sticky nswe } grid propagate . 0 grid columnconfigure . 1 -weight 1 -minsize 0 grid rowconfigure . 1 -weight 1 -minsize 0 . configure -width 100 -height 75 set a "" update foreach i {0 1 2} { lappend a [winfo width .$i]-[winfo height .$i]-[winfo ismapped .$i] } set a} {100-75-1 1-1-0 200-150-1}grid_reset 16.7test grid-16.8 {layout internal constraints} { foreach i {0 1 2 3 4} { frame .$i -bg gray -width 30 -height 25 -bd 2 -relief ridge grid .$i -row $i -column $i -sticky nswe } frame .f -bg red -width 250 -height 200 frame .g -bg green -width 200 -height 180 lower .f raise .g .f grid .f -row 1 -column 1 -rowspan 3 -columnspan 3 -sticky nswe grid .g -row 1 -column 1 -rowspan 2 -columnspan 2 -sticky nswe update set a "" foreach i {0 1 2 3 4} { append a "[winfo x .$i] " } append a ", " grid remove .f update foreach i {0 1 2 3 4} { append a "[winfo x .$i] " } append a ", " grid remove .g grid .f update foreach i {0 1 2 3 4} { append a "[winfo x .$i] " } append a ", " grid remove .f update foreach i {0 1 2 3 4} { append a "[winfo x .$i] " } set a} {0 30 70 250 280 , 0 30 130 230 260 , 0 30 113 197 280 , 0 30 60 90 120 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -