home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.tcl
- Path: sparky!uunet!utcsri!torn!cunews!nrcnet0!bnrgate!bgtys9!tewei
- From: tewei@bnr.ca (Te-Wei Sun)
- Subject: Question on binding
- Message-ID: <1992Aug14.201600.26716@bnr.ca>
- Keywords: binding
- Sender: news@bnr.ca
- Reply-To: tewei@bnr.ca (Te-Wei Sun)
- Organization: Bell-Northern Research, Ottawa, Ontario, CANADA
- Date: Fri, 14 Aug 92 20:16:00 GMT
- Lines: 82
-
-
- Hi,
-
- I wrote a short script in tk trying to bind several mouse events for
- canvas. The goal I am trying to achieve here is as follows:
-
- If I click button 1 once on the canvas, I would like to see the message
- "b1 pressed once".
-
- If I double click button 1 on the canvas, I would like to see ONLY the
- message "b1 pressed twice", not "b1 pressed once" and "b1 pressed twice",
- The same applied for triple click.
-
- If I click button 1 on the rectangle widget, I would like to see ONLY the
- message "b1 pressed once on rectangle", not "b1 pressed once" and "b1 pressed once on rectangle".
-
- If I double click button 1 on the rectangle widget, I would like to see ONLY
- the message "b1 pressed twice on rectangle" and so on for triple click.
-
-
- Is there any way I can achieve the way I would like to have my bindings?
-
- Any help will be deeply appreciated.
-
-
- The following is the script I wrote.
- ---------------------------------------------------------------------------
-
- set c .c
-
- canvas $c -relief raised
-
- button .quit -text "QUIT" -command "destroy ."
-
- pack append . .quit {bottom fillx} $c {top expand fill}
-
- #-----------------------------------------------------------------------------
- #This binding should be triggered ONLY when a SINGLE button click is detected
- #on the CANVAS, yet NOT on the RECTANGLE
- #-----------------------------------------------------------------------------
- bind $c <1> {puts stdout "b1 pressed once"}
-
- #-----------------------------------------------------------------------------
- #This binding should be triggered ONLY when a DOUBLE button click is detected
- #on the CANVAS, yet NOT on the RECTANGLE
- #-----------------------------------------------------------------------------
- bind $c <Double-ButtonPress-1> {puts stdout "b1 pressed twice"}
-
- #-----------------------------------------------------------------------------
- #This binding should be triggered ONLY when a TRIPPLE button click is detected
- #on the CANVAS, yet NOT on the RECTANGLE
- #-----------------------------------------------------------------------------
- bind $c <Triple-ButtonPress-1> {puts stdout "b1 pressed three times"}
-
- set rect [$c create rectangle 10 10 40 40 -fill black]
-
- #-----------------------------------------------------------------------------
- #This binding should be triggered ONLY when a SINGLE button click is detected
- #on the RECTANGLE widget
- #-----------------------------------------------------------------------------
- $c bind $rect <1> {puts stdout "b1 pressed once on rectangle"}
-
- #-----------------------------------------------------------------------------
- #This binding should be triggered ONLY when a DOUBLE button click is detected
- #on the RECTANGLE widget
- #-----------------------------------------------------------------------------
- $c bind $rect <Double-ButtonPress-1> {puts stdout "b1 pressed twice on rectangle
- "}
-
- #-----------------------------------------------------------------------------
- #This binding should be triggered ONLY when a TRIPPLE button click is detected
- #on the RECTANGLE widget
- #-----------------------------------------------------------------------------
- $c bind $rect <Triple-ButtonPress-1> {puts stdout "b1 pressed three times on rec
- tangle"}
-
- #end of script
-
- --
- Te-Wei Sun tewei@bnr.ca Bell-Northern Research Ottawa
- --
- Te-Wei Sun tewei@bnr.ca Bell-Northern Research Ottawa
-