When we talk about canvas bindings, we are speaking of events that are triggered in response to a mouse-click or the pressing of a key on the keyboard. You have already been introduced to one set of Canvas bindings.
When you created the graph on the Canvas in the previous step, you had to click the left mouse button on the Canvas. This triggered an event that started creating the graph. When you released the mouse button, it triggered an event that finished creating the graph. These two Canvas bindings were activated when you pressed the "Create XY Graph" button on the shortcut toolbar.
Tkgraph has a set of default Canvas bindings. These bindings are active all the time. The default Canvas bindings are:
The second Canvas binding allows you to move Canvas items, such as a graph, around the Canvas. Position the cursor over a graph on the Canvas and watch the outline of the graph turn red. When this happens, press the middle mouse button and hold it down. With the middle mouse button still pressed, move the mouse. You will see the graph follow the Cursor around the page. When you have moved the graph to the new desired position, release the middle mouse button. The graph is now fixed at this new location. Other Canvas items (labels, lines, text, etc.) can also be moved in this manner. We will play with those later.
The third Canvas binding deals with a new Tkgraph concept called the Canvas selection. This selection allows you to manipulate a single Canvas item or a set of Canvas items without making any changes to items that are not part of the selection. If, for example, there were two graphs on the Canvas, you could select one graph and modify the axis limits without changing anything on the second graph. You could then de-select the first graph, select the second graph, and make changes to the second graph only. Or you could select both graphs and change the axis limits on both graphs simultaneously. In fact, most Canvas item manipulations require you to select the item(s) that you want to modify. This is done to ensure that you don't accidentally modify an item that you didn't want to.
Selecting a Canvas item is easy. Simply press and hold the Shift key on the keyboard and then click the mouse on the desired Canvas item. The item may change color to indicate that it has been selected. Try this out on the graph on your Canvas. The graph will fill with a light gray background when it is selected. When you select a canvas item this way, all other items that have been selected are automatically deselected.
If you wish to change the selection state of one item only and leave the rest of the selection alone, the fourth Canvas binding is useful. By pressing the Control key on the keyboard and clicking the left mouse button on a canvas item you can toggle the selection state of that item. A selected Canvas item will be deselected, and a deselected item will become selected. The selection state of all other Canvas items is left alone.
Now would be a good time to draw a second graph on the Canvas. Go ahead and do this. Now play around with the two Canvas selection bindings (Control-click and Shift-click) to watch how the selection state of the graphs changes in response to the selection bindings.
Up until now we have only been working with the main Tkgraph display window. The final Canvas binding introduces a new window for our use. If you click the right mouse button anywhere on the Canvas then the Tkgraph Control Panel will appear. Go ahead and do this, but don't touch anything on the control panel. We will get back to it later. Move it somewhere out of the way, or press the "close" button at the bottom of the control panel to get rid of it for now.
![]() |
![]() |
![]() |
[Prev] | [Top] | [Next] |