1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#!/usr/bin/env wish
#==============================================================================
# Demo: wcb::callback <listbox> before selset <callback>
#
# Copyright (c) 1999-2018 Csaba Nemethi (E-mail: csaba.nemethi@t-online.de)
#==============================================================================
package require wcb
wm title . "Listboxtest #1"
#
# Add some entries to the Tk option database
#
source [file join [file dirname [info script]] option.tcl]
set dirName [file join $tk_library demos images]
#
# Frame .spacer and listbox .lb
#
frame .spacer -width 10
listbox .lb -height 0 -width 0 -background gray98
if {$tk_version < 8.5} {
set pattern [file join $dirName *.bmp]
} else {
set pattern [file join $dirName *.xbm]
}
foreach pathName [lsort [glob $pattern]] {
.lb insert end [file tail $pathName]
}
#
# Label .picture
#
label .picture -relief sunken
#
# Define a before-selset callback for .lb
#
wcb::callback .lb before selset showBitmap
#
# Callback procedure showBitmap
#
proc showBitmap {w first args} {
global dirName
set pathName [file join $dirName [$w get $first]]
.picture configure -bitmap @$pathName
}
#
# Button .close
#
button .close -text Close -command exit
#
# Manage the widgets
#
pack .spacer .lb -side left -fill y -pady 10
pack .close -side bottom -padx 10 -pady 10
pack .picture -padx 10 -pady 10
|