Posted to tcl by schelte at Mon Oct 20 13:54:10 GMT 2008view raw

  1. # This program brings up two toplevels. The Quit button on top2 does not work
  2. # because of the grab on .tree1. After bringing up the combobox list and then
  3. # clicking outside the list to hide it again the Quit button of top2 becomes
  4. # active. This happens because the [grab .tree1] command performed by the
  5. # combobox bindings fails ("grab failed: window not viewable"). However, the
  6. # same command executed by pressing F2 has no problems to set the grab on
  7. # .tree1, even though it is still not viewable. Pressing F1 will show which
  8. # widget currently has the grab, if any.
  9.  
  10. wm withdraw .
  11. frame .tree1
  12.  
  13. toplevel .tree1.top
  14. ttk::combobox .tree1.top.box -state readonly \
  15. -values {"Option 1" "Option 2" "Option 3"}
  16. label .tree1.top.grab -textvariable grab
  17. button .tree1.top.quit -text Quit -command exit
  18.  
  19. grid .tree1.top.box -padx 8 -pady 8 -sticky nwe
  20. grid .tree1.top.grab -padx 8 -pady 8
  21. grid .tree1.top.quit -padx 8 -pady 8
  22.  
  23. toplevel .top2
  24. button .top2.quit -text Quit -command exit
  25. grid .top2.quit -padx 8 -pady 8
  26.  
  27. grab .tree1
  28.  
  29. bind all <F1> {set grab [grab current]}
  30. bind all <F2> {grab .tree1}
  31.