Tcl/Tk Community Resources. The worldwide community of Tcl/Tk developers is certainly one of the most important assets available.Tcl Programming/Tk examples - Wikibooks, open books for an open world. The following examples originally appeared in the Tcler's Wiki http: //wiki. They are all in the public domain - no rights reserved. A funny cookbook. Small as it is, it can produce 9. The basic idea is to pick an arbitrary element from a list, which is easily done in Tcl with the following. Hence it s rather easy to produce a pie chart. The following code is a bit more complex, as it also determines positions for the labels of the pies. Given a canvas pathname, a bounding rectangle, and the data to display (a list of .
Note how negative values are tagged with . In addition to the buttons on screen, you can use any of expr's other functionalities via keyboard input. And, as Cameron Laird noted, this thingy is even programmable: enter for example. Tcl/Tk quick start Presented by. There are two main programs that you need on your Linux system to explore Tcl/Tk. These are tclsh and wish. The basic principle is that multiplication is done by adding logarithms, hence most of the scales are logarithmic, with uneven increments. This fun project recreates a slide rule (roughly an Aristo- Rietz Nr. Finally, the blue line represents the ? Fine movements with < Left> /< Right>. Due to rounding errors (integer pixels), this plaything is even less precise than a physical slide rule was, but maybe you still enjoy the memories.. The screenshot shows how I found out that 3 times 7 is approx. Both bindings just call one internal function each. On left- click, a line item is created on the canvas in the specified fill color, but with no extent yet, as start and end points coincide. The item ID (a number assigned by the canvas) is kept in a global variable, as it will have to persist long after this procedure has returned. Radio buttons on top allow choice of draw mode and fill color. Right- click on an item to delete it. A radio is an obvious . This simple one allows text or color mode: ? So for a mode X, we need a pair of procs, down(X) and move(X). Values used between calls are kept in global variables. First, the handlers for free- hand line drawing. Draw) . When a corner is close enough to the first one, the polygon is closed and drawn. The current mode is retrieved at runtime from the global Mode variable. I have recently picked up the habit to put this information into a string variable (which in Tcl can easily span multiple lines), so the same info is presented to the reader of the source code, and can be displayed as online help: . For this editor, I of course need a text widget, and a vertical scrollbar. As widget creation commands return the pathname, they can be nested into the manager command (pack in this case), to keep all settings for a widget in one place. This may lead to over- long lines, though. Although the scrollbar comes to the right of the text, I create and pack it first. The reason is that when a window is made smaller by the user, the widgets last packed first lose visibility. These two lines also illustrate the coupling between a scrollbar and the widget it controls: the scrollbar sends a yview message to it when movedthe widget sends a set message to the scrollbar when the view changed, for instance from cursor keys. And these two lines already give us an editor for arbitrarily long text, with built- in capabilities of cut, copy, and paste - see the text man page. Only file I/O has to be added by us to make it really usable. If so, add - undo 1 to the options to text and get full undo/redo support! For simplicity, I've limited the bindings here to a few of the function keys on top of typical keyboards. On Windows they call the native file selectors, which have a history of previously opened files, detail view (size/date etc.)When this editor is called with a filename on the command line, that file is loaded on startup (simple as it is, it can only handle one file at a time). Otherwise, they transfer file content to text widget or vice- versa. Then it opens the file, clears the text widget, reads all file contents in one go, and puts them into the text widget. PFE, MS Visual Studio) pop up an alert dialog when a file was changed on disk while being edited - that might lead to edit conflicts. Emacs shows a more subtle warning at the first attempt to change a file that has changed on disk. Here I try to emulate this feature. It is oversimplified because it does not update the mtime (file modification time) to check, once you saved it from the editor itself. So make sure to call text'watch'file again after saving. Using the global variable : . Switch pages with Left/Right cursor, or left/right mouseclick (though a stylus cannot right- click). Not many features, but the code is very compact, and with a cute little language for content specification, see example at end (which shows what I presented at the 2. Euro- Tcl convention in Nuremberg..). Anyway, here's my show. Tcl for the world. Richard Suchenwirth, Nuremberg 2. Terminology. + visible elements of writing. Byte sequences. + physical text data representation. Rendering: character - > glyph. Encoding: character < -> byte sequence. Before Unicode. * Bacon (1. Baudot: 5- bit encodings. Fieldata (6 bits), EBCDIC (8 bits). ASCII (7 bits). + world- wide . The following kinds of objects are so far available. On mouse motion, the current year is displayed in the toplevel's title. Normal items can be a single year, like the Columbus example, or a range of years, for instance for lifetimes of persons. In order to motivate her, I beefed up an earlier little function plotter which before only took one function, in strict Tcl (expr) notation, from the command line. Now there's an entry widget, and the accepted language has also been enriched: beyond exprs rules, you can omit dollar and multiplication signs, like 2x+1, powers can be written as x. Hitting < Return> in the entry widget displays the function's graph. If you need some ideas, click on the . Besides default scaling, you can zoom in or out. Moving the mouse pointer over the canvas displays x and y coordinates, and the display changes to white if you're on a point on the curve. The target was not reached: my daughter still hates math. But at least I had hours of Tcl (and function) fun again, surfing in the Cartesian plane.. Functions written in Haskell (see Playing Haskell) are applied, mostly in functional composition, to pixels to return their color value. Still, the output often is worth waiting for.. Functional composition had to be rewritten to Tcl's Polish notation - Haskell's. It normalizes the given color through dividing by the corresponding values for . It shows the predefined basic image operators, and some combinations, on a button bar. Click on one, have some patience, and the corresponding image will be displayed on the canvas to the right. You can also experiment with image operators in the entry widget at bottom - hit < Return> to try. The text of sample buttons is also copied to the entry widget, so you can play with the parameters, or rewrite it as you wish. Note that a well- formed funimj composition consists of: the composition operator . The o looks nicely bullet- ish here. At least you can watch the progress, as the target image is updated after every row. File: Tk. Photo. Lab. Edge enhancement by Laplace. The demo UI shows two images, the original on the left, the processing result on the right. You can push the result to the left with Options/Accept. See the menus for what goodies I have supplied. But what most interested me were . As an example, the convolution matrix. These. 0 - 1 0 - 1 - 1 - 1. Hence I made them generic, and they take a function name that is applied to every pixel rgb, resp. They are instantiated by an alias that sets the function fancily as a lambda. For graylevel images, the displayed .
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
September 2016
Categories |