home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!ucbvax!ansa.co.uk!eo
- From: eo@ansa.co.uk (Ed Oskiewicz)
- Newsgroups: comp.lang.tcl
- Subject: Bug in menus of radio buttons
- Message-ID: <9209081508.AA22137@caligula.ansa.co.uk>
- Date: 8 Sep 92 15:08:14 GMT
- Sender: daemon@ucbvax.BERKELEY.EDU
- Lines: 80
-
-
- The little program below exercises a bug in tk menus.
-
- What I'm trying to do is have two menus each with identical contents which are
- to operate independantly. I have made each entry a radio button (because it
- seemed like a good idea at the time) as I wanted to remind the user what the
- current selection was.
-
- The bug is that you have two menus with identical contents then they behave as
- though you had two menu buttons onto the same menu.
-
- To see this run the script below, it will produce a pair of menu buttons each
- of which lists all objects in your current directory.
-
- if you select an entry in one button it changes the text in the menu button
- and highlights the entry selected. Now if you select the other button you find
- it's menu has the PREVIOUS SELECTION already highlighted. If you make a new
- selection and switch back to the first button then it shows your new selection
- already highlighted. I.e. the two buttons behave as though they are sharing a
- menu when I would expect each menu to operate independently.
-
- The behaviour I would expect is manifested if I make the menu entries
- textually different, to see this go to the for loop and comment out the first
- AddDMenuItem and enable the second - note I've added a space before each
- directory name.
-
- N.B. this has been abstracted from a larger script with unwanted detail
- excised hence the apparent verbosity.
-
- Can anyone shed some light on this behaviour?
-
- ------ cut here --------
- #!/usr/local/wish -f
-
- frame .f1 -relief raised
- frame .f2 -relief raised
-
- pack append . .f1 {top expand fill} .f2 {top expand fill}
-
- proc AddMB {f} {
- menubutton $f.fm -menu $f.fm.m -borderwidth 2 -relief raised
- menu $f.fm.m
- pack append $f $f.fm {left fill expand}
- }
-
- proc Label {s m l} {
- $m configure -text "$s: $l"
- }
-
- proc AddDMenuItem {m l} {
- $m.m add radio -label $l -command "Label \"First Folder \" $m $l"
- }
-
- proc AddCMenuItem {m l} {
- $m.m add radio -label $l -command "Label \"Second Folder \" $m $l"
- }
-
- # Create the menu buttons, and provide initial labels
- AddMB .f1
- AddMB .f2
-
- Label "1st button" .f1.fm "<none>"
- Label "2nd button" .f2.fm "<none>"
- # I would expect each radio button menu to operate separately, but they don't
- # The commented out line gives the behaviour I would expect
-
- foreach i [exec ls -1] {
- AddDMenuItem .f1.fm $i
- # AddDMenuItem .f1.fm " $i"
- AddCMenuItem .f2.fm $i
- }
- ------ cut here --------
- Cheers,
-
- Ed Oskiewicz
-
- email: eo@ansa.co.uk (mcsun!uknet!ansa!eo) ANSA,
- tel: +44 223 323 010 Poseidon House,
- fax: +44 223 359 779 Castle Park,
- Cambridge CB3 0RD, UK
-