hi,all
First,thanks very much for ulis's help that time.Now I can't realize the insert function.Can someone help me?
I want to insert a button in the desinged location and work for it a long time but fialed.
The program is bolow:
# proc bgerror (to see what happens behind the scene)
proc bgerror {args} { tk_messageBox -message "bgerror: $args" }
# proc forward
proc forward {} {
global wc x1 x2 y i bli
# type 1
lappend bli 1
# create label & entry
label $wc.labe$i -text "$i forward" -relief raised -bg navy -fg white
$wc create window $x1 $y -window $wc.labe$i -anchor n -tags item
entry $wc.entry$i
$wc create window $x2 $y -window $wc.entry$i -anchor n -tags item
# update globals
incr i
incr y 20
# debug
puts "forward: created label $i, entry $i"
}
# proc end
proc end {} {
global wc x1 x2 y i bli
# type 9
lappend bli 9
# create label
label $wc.labe$i -text "$i end" -relief raised
$wc create window $x1 $y -window $wc.labe$i -anchor n -tags item
# update globals
incr i
incr y 20
# debug
puts "end: created label $i"
}
# proc del
proc del {} {
global wc x1 x2 y i bli
# check if empty
if {$i == 1} { return; # no more labels }
# current row
incr i -1
# delete folowing type
set type [lindex $bli end]
if {[lsearch {1 2 3 4 5 6 8} $type] > -1} {
destroy $wc.labe$i
destroy $wc.entry$i
puts "delete: deleted label $i, entry $i"
} else {
destroy $wc.labe$i
puts "delete: deleted label $i"
}
# update globals
incr y -20
set bli [lrange $bli 0 end-1]
# debug
puts "delete: deleted label $i"
}
#proc insert {} {
}
#the main frame
set w .main
toplevel $w
#The left frame
set w1 $w.one
frame $w1 -width 200 -height 400 -bg grey50
button $w1.b2 -text "forward" -width 10 -command forward
button $w1.b10 -text "end" -width 10 -command end
pack $w1 -side left -fill x
pack $w1.b2 $w1.b10 -side top -expand yes -pady 2
#the middle frame
set w2 $w.two
frame $w2 -width 200 -height 50 -bg white
frame $w2.frame
frame $w2.bottom -width 200 -height 50 -bg blue
pack $w2 -side left -fill x
pack $w2.frame -side top
pack $w2.bottom -side bottom
#the midllemiddle frame
set wc $w2.frame.c
canvas $wc -scrollregion {0 0 200 2400} -width 200 -height 300 -relief sunken -borderwidth 2 -xscrollcommand "$w2.frame.hscroll set" -yscrollcommand "$w2.frame.vscroll set"
scrollbar $w2.frame.vscroll -command "$wc yview"
scrollbar $w2.frame.hscroll -orient horizon -command "$wc xview"
grid $wc -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
grid $w2.frame.vscroll -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news
grid $w2.frame.hscroll -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news
grid rowconfig $w2.frame 0 -weight 1 -minsize 0
grid columnconfig $w2.frame 0 -weight 1 -minsize 0
#middlebottom
button $w2.bottom.1 -text delete -width 5 -command del
button $w2.bottom.2 -text insert -width 5 -command insert
pack $w2.bottom.1 $w2.bottom.2 -side left -fill both -expand true
# labels x position
set x1 20
# entries x position
set x2 110
# next widget y position
set y 5
# next row
set i 1
# types list (1: forward, 9: end)
set bli {}
THANKS
First,thanks very much for ulis's help that time.Now I can't realize the insert function.Can someone help me?
I want to insert a button in the desinged location and work for it a long time but fialed.
The program is bolow:
# proc bgerror (to see what happens behind the scene)
proc bgerror {args} { tk_messageBox -message "bgerror: $args" }
# proc forward
proc forward {} {
global wc x1 x2 y i bli
# type 1
lappend bli 1
# create label & entry
label $wc.labe$i -text "$i forward" -relief raised -bg navy -fg white
$wc create window $x1 $y -window $wc.labe$i -anchor n -tags item
entry $wc.entry$i
$wc create window $x2 $y -window $wc.entry$i -anchor n -tags item
# update globals
incr i
incr y 20
# debug
puts "forward: created label $i, entry $i"
}
# proc end
proc end {} {
global wc x1 x2 y i bli
# type 9
lappend bli 9
# create label
label $wc.labe$i -text "$i end" -relief raised
$wc create window $x1 $y -window $wc.labe$i -anchor n -tags item
# update globals
incr i
incr y 20
# debug
puts "end: created label $i"
}
# proc del
proc del {} {
global wc x1 x2 y i bli
# check if empty
if {$i == 1} { return; # no more labels }
# current row
incr i -1
# delete folowing type
set type [lindex $bli end]
if {[lsearch {1 2 3 4 5 6 8} $type] > -1} {
destroy $wc.labe$i
destroy $wc.entry$i
puts "delete: deleted label $i, entry $i"
} else {
destroy $wc.labe$i
puts "delete: deleted label $i"
}
# update globals
incr y -20
set bli [lrange $bli 0 end-1]
# debug
puts "delete: deleted label $i"
}
#proc insert {} {
}
#the main frame
set w .main
toplevel $w
#The left frame
set w1 $w.one
frame $w1 -width 200 -height 400 -bg grey50
button $w1.b2 -text "forward" -width 10 -command forward
button $w1.b10 -text "end" -width 10 -command end
pack $w1 -side left -fill x
pack $w1.b2 $w1.b10 -side top -expand yes -pady 2
#the middle frame
set w2 $w.two
frame $w2 -width 200 -height 50 -bg white
frame $w2.frame
frame $w2.bottom -width 200 -height 50 -bg blue
pack $w2 -side left -fill x
pack $w2.frame -side top
pack $w2.bottom -side bottom
#the midllemiddle frame
set wc $w2.frame.c
canvas $wc -scrollregion {0 0 200 2400} -width 200 -height 300 -relief sunken -borderwidth 2 -xscrollcommand "$w2.frame.hscroll set" -yscrollcommand "$w2.frame.vscroll set"
scrollbar $w2.frame.vscroll -command "$wc yview"
scrollbar $w2.frame.hscroll -orient horizon -command "$wc xview"
grid $wc -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
grid $w2.frame.vscroll -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news
grid $w2.frame.hscroll -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news
grid rowconfig $w2.frame 0 -weight 1 -minsize 0
grid columnconfig $w2.frame 0 -weight 1 -minsize 0
#middlebottom
button $w2.bottom.1 -text delete -width 5 -command del
button $w2.bottom.2 -text insert -width 5 -command insert
pack $w2.bottom.1 $w2.bottom.2 -side left -fill both -expand true
# labels x position
set x1 20
# entries x position
set x2 110
# next widget y position
set y 5
# next row
set i 1
# types list (1: forward, 9: end)
set bli {}
THANKS