Tk Source Code

View Ticket
Login
Ticket UUID: 1288433
Title: LisboxSelect event triggers when listbox state is disabled
Type: Bug Version: obsolete: 8.4.11
Submitter: treincke Created on: 2005-09-12 08:22:09
Subsystem: 09. [listbox] Assigned To: fvogel
Priority: 6 Severity: Minor
Status: Closed Last Modified: 2016-01-06 20:20:27
Resolution: Fixed Closed By: fvogel
    Closed on: 2016-01-06 20:20:27
Description:
This code

   pack [listbox .l] 
   .l insert end 1 2 3 
   bind .l <<ListboxSelect>> {puts click!} 
   .l configure -state disabled

shows that the ListBoxSelect event will be triggered regardless of the state 
of the listbox. Although the listbox is "disabled" so no selection can be 
made, the event fires, indicating a selection has been made.

Jeff Hobbs writes on this subject:

(http://groups.google.com/group/comp.lang.tcl/browse_thread/thread/
b63e43a981b6a698/93341e895ba0c054)

"Hmm, I would cal that a low priority bug.  It appears that the 
ListboxSelect is merely triggering unnecessarily.  The items 
are not actually being selected, so functionally it is all OK, 
but we could avoid the ListboxSelect, so we should."

A workaround on script level is to check for the listbox state in the code for 
the binding:

bind .l <<ListboxSelect>> {
   # abort, if disabled: 
   if {[%W cget -state]=="disabled"} {break} 
   # else do the normal action:
   # ...
}
User Comments: fvogel added on 2016-01-06 20:20:27:
Fix pushed in core-8-5-branch and trunk.

fvogel added on 2015-12-30 22:14:07:
Fix now proposed in branch bug-1288433fff to prevent <<ListboxSelect>> from firing when the listbox is in disabled state.

Precisions on when the <<ListboxSelect>> event fires are added in the listbox documentation.

Corresponding testcase listbox-31.1 added.

treincke added on 2006-03-13 16:10:11:
Logged In: YES 
user_id=370915

I think, to fix the problem, the only changes necessary are 
in the library file 'listbox.tcl' in the procs 

- ::tk::ListboxBeginSelect
- ::tk::ListboxBeginToggle
- ::tk::ListboxMotion

where the line

 if {[$w cget -state]=="disabled"} {return}

should be added at the top of the body. I don't want to 
submit this as patch though, because I have not tested all 
possible cases on all platforms, but on Linux, this fixes 
all troubles and works nicely.