programming.nbk: Home | Index | Next Page: Tk: Dialog Boxes | Previous Page: Tk: commands


 Tk: commands: bind

Syntax:

bind path script

stands for the sequence of button/mouse presses. It should be given in the following pattern...

. For example...

- Control+Alt+T.

Control and Alt are the modifiers and Key is the type with t as the detail. See the next example and you will understand.

#The helping function
proc help {} {
	tk_messageBox -message {Did you ask of help?
You ain't getting any.
Ha Ha Ha!}
}

#This happens at double-click
proc double {} {
	tk_messageBox -message {You double clicked something.
This script is simple - so it won't display what you clicked on.
But if you want a sript that is able to do that, 
write to me at binnyva(at)hotmail(dot)com
and I will send you a better script.}
}

label .lab -text " The Bind command " -font {ansi 12 bold}
listbox .lst
.lst insert end "Don't double-click this."
.lst insert end "Don't double-click this either."
.lst insert end "Don't even think of double-clicking this."
.lst insert end "You may double-click this."
.lst insert end "No. Negative. Nay. Nope. Get the message?"
#Bind the double click event to the list box
bind .lst <Double-ButtonPress-1> { double }

label .keys  -justify left -text {Press any of the following...
Control+A
Control+Shift+A
Control+Alt+T
Right click
Control+Escape}

pack .lab .lst .keys -expand 1 -fill x ;#Pack everything

#Exit when the escape key is pressed
bind . <Key-Escape> { exit }
#Shows a helping dialog box when F1 is pressed
bind . <Key-F1> { help }
#Binds misc keys.
bind . <Control-Key-a> \
 { tk_messageBox -message "You pressed Control+A, did'nt you?" } ;#Control+A
bind . <Control-Key-A> \
 { tk_messageBox -message "Control+Shift+A, right?" } ;#Control+Shift+A
bind . <Control-Alt-Key-t> \
 { tk_messageBox -message "Control, Alt and T" } ;#Control+Alt+T
bind . <ButtonPress-3> \
 { tk_messageBox -message "The right way to click." } ;#Right click
bind . <Control-Key-Escape> \
 { tk_messageBox -message {You must be a married man. 
What you pressed remindes married men of what they never will have
 - Control or Escape.}
} ;#Control+Escape 

programming.nbk: Home | Index | Next Page: Tk: Dialog Boxes | Previous Page: Tk: commands


Notebook exported on Monday, 7 July 2008, 18:56:06 PM Eastern Daylight Time