Hello, World!
Example 34-2 creates an object that you can drag around with the mouse. It introduces the use of tags to classify objects. In this case the movable tag gets bindings that let you drag the item, so any item with the movable tag shares this behavior. The example uses Scrolled_Canvas from Example 34-1. When you use a scrolled canvas, you must map from the view coordinates reported by bindings to the canvas coordinates used to locate objects:
Example 34-2 The canvas “Hello, World!” example.
proc CanvasHello {} { set can [Scrolled_Canvas .c -width 400 -height 100 \ -scrollregion {0 0 800 400}] pack .c -fill both -expand true # Create a text object on the canvas $can create text 50 50 -text "Hello, World!" -tag movable # Bind actions ... |
Get Practical Programming in Tcl & Tk, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.