Posted to tcl by jeremy_c at Sat Jan 30 19:54:55 GMT 2010view raw

  1. # Focus Race... Drop down a combo box and watch
  2. # your CPU and Memory fly sky high!
  3. #
  4. # In my app, the focus race was not so obvious as the <FocusIn> type calls were in
  5. # different snit::widgets and made sense when a widget stood alone, but when they
  6. # started adding up and then the parent having a <FocusIn> as well, things went
  7. # crazy.! Select an item from one of the drop downs, that causes everything to loose focus
  8. # and the drop down list window gets focus. As soon as that widget gives focus back
  9. # to the parent, be ready to hit the kill process button!
  10.  
  11. package require Tk
  12.  
  13. ttk::frame .f1
  14. ttk::combobox .f1.c1 -values {A B C}
  15. pack .f1.c1
  16. bind .f1 <FocusIn> { focus -force .f1.c1 }
  17.  
  18. ttk::frame .f2
  19. ttk::combobox .f2.c2 -values {D E F}
  20. pack .f2.c2
  21. bind .f2 <FocusIn> { focus -force .f2.c2 }
  22.  
  23. pack .f1 .f2
  24.  
  25. bind . <FocusIn> { focus -force .f1 }