Tk Source Code

View Ticket
Login
Ticket UUID: 1581435
Title: menu index wrong if label is an integer
Type: Bug Version: obsolete: 8.4.13
Submitter: reowen Created on: 2006-10-20 17:57:19
Subsystem: 10. Generic Menus Assigned To: fvogel
Priority: 6 Severity: Minor
Status: Closed Last Modified: 2015-09-06 19:43:05
Resolution: Fixed Closed By: fvogel
    Closed on: 2015-09-06 19:43:05
Description:
If a menu contains an item whose label is an integer,
then menu index returns the value of that menu item,
or if the integer is too large, then it returns
the index of the last item in the menu.

Here is a procedure to see this.
Enter it into wish and select menu items to see the index.
The index of entry "3" is reported as 3, but should be 1.

menubutton .mb -m .mb.menu -text testmenu
pack .mb
set m [menu .mb.menu]
$m add command -label foo -command {puts "foo: [$m index foo]"}
$m add command -label 3 -command {puts "3: [$m index 3]"}
$m add command -label 3a -command {puts "3: [$m index 3a]"}
$m add command -label bar -command {puts "bar: [$m index bar]"}
$m add command -label baz -command {puts "baz: [$m index baz]"}

I saw this on ActiveState Aqua Tcl/Tk 8.4.13 on MacOS X 10.4.7. I have 
not tried to duplicate it on other operating systems nor with 8.4.14 
(since the ActiveState version is not yet available).
User Comments: fvogel added on 2015-09-06 19:43:05:
Merged to core-8-5-branch and trunk.

fvogel added on 2015-09-02 20:32:45:
Proposal for a fix in the documentation in branch bug-1581435fff

A test case has also been augmented to check the precedence order in the matching process of the index string.

vincentdarley added on 2006-10-22 01:59:14:
Logged In: YES 
user_id=32170

This is the correct behaviour. The man page specifies that '$m index $X' 
interprets 'X' as a number or as a pattern. It seems specifying as a number takes 
precedence.

fvogelnew1 added on 2006-10-21 15:31:04:
Logged In: YES 
user_id=1245417

Reproduced on WinXP with 8.4.13.