Posted to tcl by mjanssen at Fri Dec 08 20:36:13 GMT 2006view raw

  1. package require Tk
  2.  
  3. text .t
  4. pack .t
  5. .t insert 1.0 test
  6.  
  7. proc save_state { widget } {
  8. variable state
  9. set state($widget) [$widget get 1.0 end]
  10. }
  11.  
  12. proc restore_state {widget} {
  13. variable state
  14. $widget delete 1.0 end
  15. $widget insert 1.0 $state($widget)
  16. bind $widget <KeyPress> {}
  17. }
  18.  
  19. proc display_result {} {
  20. save_state .t
  21. .t delete 1.0 end
  22. .t insert 1.0 {this is the result}
  23. bind .t <KeyPress> {restore_state .t ; break}
  24. }
  25.  
  26. display_result
  27.  
  28. # from here everything is handled by events