Posted to tcl by jenglish at Tue Jul 11 01:22:24 GMT 2006view raw

  1. package require Tk
  2.  
  3. option add *tearOff false
  4.  
  5. variable mute 0
  6.  
  7. proc muteChanged {} {
  8. global mute
  9. puts "mute=$mute"
  10. }
  11.  
  12. . configure -menu [menu .menu]
  13. .menu add cascade -label "Test" -menu [menu .menu.test] -underline 0
  14. .menu.test add checkbutton \
  15. -label "Mute" -variable mute -command muteChanged \
  16. -underline 0 -accelerator Ctrl-M \
  17. ;
  18.  
  19. # The <Alt-KeyPress-t> accelerator automatically pops down the "Test" menu,
  20. # and the "m" mnemonic will automatically toggle the "Mute" entry.
  21. # However, you need to add the Ctrl-M accelerator by hand:
  22. #
  23. bind . <Control-KeyPress-m> { toggleMute }
  24. proc toggleMute {} {
  25. global mute;
  26. set mute [expr {!$mute}]
  27. muteChanged
  28. }
  29.  
  30. pack [entry .e] -expand false -fill x ; focus .e

Comments

Posted by tom at Tue Jul 11 01:32:30 GMT 2006 [text] [code]

This code by jenglish solves the problem of updating the check-mark of the menu-entry when using accelerator key. So the status is shown always correctly. Great code. Thx a lot jenglish.