Tcl-Tk Code
'Snippets' Sources

especially for
BIND statements
(for various
events on widgets)

Snippets from scripts in
the FE 'tkGooies' system
--- and from other sources.

(Snippets to facilitate
development of Tk GUI's.)
(FE = Freedom Environment)

This animated-Gif was
created with the
'wheeeMorph' script
of the FE 'tkGooies' system.

Note the nice morphing
(movement and merging)
of the nostrils.

FE Home page > FE Downloads page >

FE 'tkGooies' Download page >

'tkGooies' Description page >

'Tcl-Tk Code Snippets Sources' page >

This 'Tcl-Tk BIND Statement Sources' page

! Note !
More links to sources of Tcl-Tk code
for BIND STATEMENTS may be added
--- as more and more scripts are added
to the FE 'tkGooies' subsystem.

< Go to Table of Contents, below >
(SKIP THIS INTRO)

INTRODUCTION to BIND code snippets:

As I develop more and more Tk GUI scripts in the FE 'tkGooies' subsystem --- in the group of FE (Freedom Environment) subsystems, I find it extremely helpful to copy 'snippets' of 'bind' code from an 'old' tkGooie script, for use in a new 'tkGooie' --- and then make a few changes of variable names and widget names, as needed.

As I publish a script of the 'tkGooies' system on the CODE pages that are available via the 'tkGooies' Description page, I hope that that particular 'tkGooie' script may help others to learn to make Tcl-Tk scripts that are of interest to them.

In the course of these activities ('tkGooie' code development and 'tkGooie' code publishing), I realized that it will be of help to me --- and to other potential 'Tclers' --- to have a web page that points to sources of various kinds of Tcl-Tk code 'snippets'.

I quickly realized that, when I am looking for a Tcl-Tk code snippet, I am usually looking for a snippet that is of one of 3 general kinds:

  • a WIDGET -
    an example of DEFINITION (and packing) of a widget

  • a BINDING -
    an example of an EVENT binding on a widget

  • a PROC -
    an example to perform a SPECIFIC FUNCTION, such as file-reading, or file-writing, or plotting lines/ovals/polygons on a canvas, or plotting pixels in a photo-image on a canvas, or performing a certain kind of calculation, or whatever.

It is the purpose of this page to provide examples of BIND STATEMENTS --- via links to web pages that present Tcl-Tk code.

---

Most of the links (below) will be to the 'CODE pages' of my 'tkGooies' system --- pages of this FE (Freedom Environment) web site, www.freedomenv.com.

But some links may be 'external' links --- to helpful pages at the Tcler's wiki --- wiki.tcl.tk --- or elsewhere on the web.


Organization of the links below :

There are such a wide variety of 'code snippets', that it is difficult to devise a single way of organizing the links.

There is a standardized Tk coding structure that I use in the development of 'tkGooie' scripts.

I describe that coding structure on the page A Canonical Structure for Tk Code --- and variations.

In that coding structure, I basically organize the code to include 3 main sections:

  • widget definitions
    (the layout of the GUI) --- typically involving defining 'frame' widgets, and then widgets within those frames --- widgets like 'button' widgets, 'label' widgets, 'entry' widgets, etc.

  • 'bind' statements,
    if any are needed in addition to the default bindings that are provided with the Tk widgets.

    The 'bind' statements specify code to be executed when certain 'events' occur, such as moving a mouse on a Tk 'canvas' widget.

  • procs (procedures)
    which may involve various kinds of algorithms to perform calculations, to draw images, to read files, to write files, to execute external programs, etc.

In providing the links below, I provide links for EVENT-BINDINGS.

A 'Table of Contents' section below can be used to take you to a section of the page below --- where each section corresponds to an event-binding --- like 'Release' or 'Press' events on a mouse button --- or 'Move' or 'Leave' events with a mouse cursor --- or 'Home' or 'End' or 'PageDown' or 'PageUp' keyboard events.

Note that the event types that are most commonly used in bindings are those for user actions such as key presses (or releases) or changes in the pointer position.

Examples of Tk event names:

  • 'Button' or 'ButtonPress'
    --- indicating a mouse button was pressed.

  • 'ButtonRelease'
    --- indicating a mouse button was released.

      Note:
      'ButtonRelease' is used more often than 'ButtonPress' in the 'tkGooie' scripts.

  • 'Enter'
    --- indicating the pointer moved into a window/widget.

  • 'Leave'
    --- indicating the pointer moved out of a window/widget.

  • 'Motion'
    --- indicating the pointer moved from one point to another within a window/widget.

  • 'Key' or 'KeyPress'
    --- indicating a key was pressed.

  • 'KeyRelease'
    --- indicating a key was released.

  • 'Return'
    --- indicating the Return/Enter key was pressed.

The coder usually has a widget-type in mind --- to which an action will be 'bound', to respond to a particular user action on the widget.

For example, the 'Return' event is usually bound to an 'entry' widget.

So the items in the Table of Contents below will be specified by a combination of a widget-name and an event-name.

    Note that some of the 'canvas' bindings may be 'canvas-item-TAG' bindings.

If this organization by widget-and-event name does not work for you, and it would be more helpful to seek 'bind' examples by a 'function' that you want to perform, you can look at the PROCS code-snippets page which is organized by 'function'.

The Tk GUI scripts which provide that function may also have 'bind' statements that use procs to perform that function.

Enough of this introduction.

Below is the 'Table of Contents' --- a table of links.

The table of contents below provides links to sections of THIS web page that contain links to take the reader to locally-stored (or remotely-stored) code --- code that contains snippets that may help in making more Tk GUI's.

Table of Contents:

(links to sections of this page, below)

(in alphabetic order by widget-name
and then
alphanumeric order by event-name)

End of Table of Contents.

Start of Sections of Links to Code Snippets.

(in alphabetical order by widget-name
and then
alphanumeric order by event-name)

Some Sources of snippets for
'button' and 'ButtonPress-1' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'button' and 'ButtonRelease-1' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'canvas' and 'Any-Enter' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'canvas' and 'Any-Leave' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'canvas' and 'ButtonPress-1' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'canvas' and 'ButtonPress-2' bindings:

  • wheeeDiagram
    'ButtonPress-2' mouse binding on a 'canvas' widget

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'canvas' and 'ButtonRelease-1 bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'canvas' and 'ButtonRelease-2' bindings:

  • wheeeDiagram
    'ButtonRelease-2' mouse binding on a 'canvas' widget

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'canvas' and 'ButtonRelease-3' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'canvas' and 'Button1-Motion' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'canvas' and 'Button2-Motion' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'canvas' and 'MouseWheel' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'checkbutton' and 'ButtonRelease-1' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'entry' and 'ButtonRelease-1' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'entry' and 'ButtonRelease-3' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'entry' and 'KeyRelease' bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'entry' and 'Return' key bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'radiobutton' and 'ButtonRelease-1' bindings:

  • wheeeDiagram
    provides 'ButtonRelease-1' mouse bindings on 7 'radiobutton' widgets

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'text' and 'End' key bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'text' and 'Home' key bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'text' and 'Key-Down' (DownArrow) Key bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'text' and 'Key-Up' (UpArrow) key bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'text' and 'Next' (PageDown) key bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Some Sources of snippets for
'text' and 'Prior' (PageUp) key bindings:

< Go to Table of Contents, above. >

< Go to Top of this page. >

Bottom of this page of
Tcl-Tk Code 'Snippets' Sources
for Widget-and-Event BINDINGS

--- a page of links to Tcl-Tk source code
--- mostly links to CODE pages
of the FE 'tkGooies' system.

To return to a previously visited web page, click on the Back button of your web browser a sufficient number of times. OR, use the History-list option of your web browser.
OR ...

< Go to Table of Contents, above. >

< Go to Top of Page, above. >

Page history:

Page was created 2016 Nov 04.

Page was changed 2018 Aug 19.
(Added css and javascript to try to handle text-size for smartphones, esp. in portrait orientation.)

Page was changed 2019 Jun 18.
(Specified an image width in percents to size the image according to width of the browser window. Also some rather minor reformatting of the page was done.)