home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / tcl / 1195 < prev    next >
Encoding:
Text File  |  1992-08-14  |  3.6 KB  |  95 lines

  1. Newsgroups: comp.lang.tcl
  2. Path: sparky!uunet!utcsri!torn!cunews!nrcnet0!bnrgate!bgtys9!tewei
  3. From: tewei@bnr.ca (Te-Wei Sun)
  4. Subject: Question on binding
  5. Message-ID: <1992Aug14.201600.26716@bnr.ca>
  6. Keywords: binding
  7. Sender: news@bnr.ca
  8. Reply-To: tewei@bnr.ca (Te-Wei Sun)
  9. Organization: Bell-Northern Research, Ottawa, Ontario, CANADA
  10. Date: Fri, 14 Aug 92 20:16:00 GMT
  11. Lines: 82
  12.  
  13.  
  14. Hi,
  15.  
  16. I wrote a short script in tk trying to bind several mouse events for
  17. canvas. The goal I am trying to achieve here is as follows:
  18.  
  19. If I click button 1 once on the canvas, I would like to see the message
  20. "b1 pressed once".
  21.  
  22. If I double click button 1 on the canvas, I would like to see ONLY the
  23. message "b1 pressed twice", not "b1 pressed once" and "b1 pressed twice",
  24. The same applied for triple click.
  25.  
  26. If I click button 1 on the rectangle widget, I would like to see ONLY the
  27. message "b1 pressed once on rectangle", not "b1 pressed once" and "b1 pressed once on rectangle".
  28.  
  29. If I double click button 1 on the rectangle widget, I would like to see ONLY
  30. the message "b1 pressed twice on rectangle" and so on for triple click.
  31.  
  32.  
  33. Is there any way I can achieve the way I would like to have my bindings?
  34.  
  35. Any help will be deeply appreciated.
  36.  
  37.  
  38. The following is the script I wrote.
  39. ---------------------------------------------------------------------------
  40.  
  41. set c .c
  42.  
  43. canvas $c -relief raised
  44.  
  45. button .quit -text "QUIT" -command "destroy ."
  46.  
  47. pack append . .quit {bottom fillx} $c {top expand fill}
  48.  
  49. #-----------------------------------------------------------------------------
  50. #This binding should be triggered ONLY when a SINGLE button click is detected
  51. #on the CANVAS, yet NOT on the RECTANGLE
  52. #-----------------------------------------------------------------------------
  53. bind $c <1> {puts stdout "b1 pressed once"}
  54.  
  55. #-----------------------------------------------------------------------------
  56. #This binding should be triggered ONLY when a DOUBLE button click is detected
  57. #on the CANVAS, yet NOT on the RECTANGLE
  58. #-----------------------------------------------------------------------------
  59. bind $c <Double-ButtonPress-1> {puts stdout "b1 pressed twice"}
  60.  
  61. #-----------------------------------------------------------------------------
  62. #This binding should be triggered ONLY when a TRIPPLE button click is detected
  63. #on the CANVAS, yet NOT on the RECTANGLE
  64. #-----------------------------------------------------------------------------
  65. bind $c <Triple-ButtonPress-1> {puts stdout "b1 pressed three times"}
  66.  
  67. set rect [$c create rectangle 10 10 40 40 -fill black]
  68.  
  69. #-----------------------------------------------------------------------------
  70. #This binding should be triggered ONLY when a SINGLE button click is detected
  71. #on the RECTANGLE widget
  72. #-----------------------------------------------------------------------------
  73. $c bind $rect <1> {puts stdout "b1 pressed once on rectangle"}
  74.  
  75. #-----------------------------------------------------------------------------
  76. #This binding should be triggered ONLY when a DOUBLE button click is detected
  77. #on the RECTANGLE widget
  78. #-----------------------------------------------------------------------------
  79. $c bind $rect <Double-ButtonPress-1> {puts stdout "b1 pressed twice on rectangle
  80. "}
  81.  
  82. #-----------------------------------------------------------------------------
  83. #This binding should be triggered ONLY when a TRIPPLE button click is detected
  84. #on the RECTANGLE widget
  85. #-----------------------------------------------------------------------------
  86. $c bind $rect <Triple-ButtonPress-1> {puts stdout "b1 pressed three times on rec
  87. tangle"}
  88.  
  89. #end of script
  90.  
  91. -- 
  92. Te-Wei Sun      tewei@bnr.ca      Bell-Northern Research   Ottawa
  93. --
  94. Te-Wei Sun      tewei@bnr.ca      Bell-Northern Research   Ottawa
  95.