Attachment "treeview_crash.tcl" to
ticket [f4213443]
added by
marc_culler
2024-07-19 13:32:52.
package require Tk
wm withdraw .
#-------------------------------------------------------------------------------
proc Refresh {} {
# Proc called : - at the launch of script
# - by binding on menu item "(All)" or "10" (after right-click on the label "Line")
# Purpose : create some checkbuttons and labels whose number vary with variable "::maxLine_New"
# delete pre-existing checkbuttons and labels :
for {set i 1} {$i <= $::maxLine_Old} {incr i} {
destroy .test.chb$i .test.line$i
}
# Create some checkbuttons and labels :
for {set i 1} {$i <= $::maxLine_New} {incr i} {
set ::vect_Actif($i) 1
grid [checkbutton .test.chb$i -variable ::vect_Actif($i)] -row $i -column 0
grid [ttk::label .test.line$i -text $i] -row $i -column 1
}
}
#-------------------------------------------------------------------------------
toplevel .test
wm protocol .test WM_DELETE_WINDOW {exit}
grid [ttk::label .test.headerActif -text Actif] -row 0 -column 0
grid [ttk::label .test.headerLine -text Line] -row 0 -column 1
bind .test.headerLine <3> {
# Right-click on the label "Line" : create a menu widget ".menuDeroulant"
# and display 2 menu items : "(All)" and "10"
# click on one menu item to change the value of the variables
# "::maxLine_Old" and "::maxLine_New"
# and call proc Refresh
destroy .menuDeroulant
menu .menuDeroulant
# menu item "(All)" (set ::maxLine_New to 20)
set ::chbVar(All) 0
.menuDeroulant add checkbutton -label "(All)" -variable ::chbVar(All) \
-command {
destroy .menuDeroulant
set ::maxLine_Old $::maxLine_New
set ::maxLine_New 20
Refresh
}
# menu item "10" (set ::maxLine_New to 10)
if {$::maxLine_New == 10} {
set ::chbVar(10) 1
} else {
set ::chbVar(10) 0
}
.menuDeroulant add checkbutton -label 10 -variable ::chbVar(10) \
-command {
destroy .menuDeroulant
set ::maxLine_Old $::maxLine_New
set ::maxLine_New 10
Refresh
}
# Display all items of the menu in widget ".menuDeroulant"
set x [expr {[winfo rootx .test] + %x + 1}]
set y [expr {[winfo rooty .test] + %y + 1}]
tk_popup .menuDeroulant $x $y
}
# Display 20 pairs of checkbuttons et labels
set ::maxLine_Old 0 ;# number of pre-existsing pairs
set ::maxLine_New 20 ;# number of pairs to create
Refresh