The "-after" option tells the packer to pack the frame containg the text widget and scrollbar below the top menubar and the option "-side" tells it to pack the vertical scrollbar to the left of the text widget. Make ed. The options -text, -menu and -underline are specified for each button.
The -underline option enables the menu to be invoked without using the mouse and from the keyboard by holding the Alt down and typing the underlined character within the window. The -menu option associates a menu with the menubutton. Executing this script will now give the following: Pulldown Menus You now need to attach menu entries to each of these menubuttons and create pulldown menus. Append to the script the following: create pulldown menus menu.
Each menu entry has -command option to associate the action to be invoked if that entry is selected. A menu entry is selected, by pressing the left mouse button on the top menubutton, traversing the pulldown menu while holding the button down and releasing it on the entry. When an entry is selected the action is invoked and the menu will be unposted. Cascading Menus A "cascade button is added to the menu instead of a command or a toggle or a check button to make another level of subservient walk-through menu.
The cascade button appears with an arrow pointing left to indicate the additional level of choices. The script below attaches a cascade button for the menu entry labelled "Find Selection". The menu attached to this cascade allows the user to specify whether the serach should be carried out "Forward" or "Backward" from the current insertion point. Find menu menu. Input focus is set to the menubar by the command focus.
This is needed for making keystrokes and keyboard traversal recognised. Tk menus are tear-off by default and clicking on the dotted lines achieves it. The scripts are in the three files message. The fileselectionbox script is contributed software with some minor changes. The script is in the Cokkbook's code subdirectory under ch3 and is named filesel. Copy that file into your current working directory.
The reader should be able to use it as an independent unit. The fileselectionbox is simple and looks like: Warning message When the user selects a "SaveAs" option but subsequently changes his mind and cancels the fileselectionbox, a pop-up warning message that the contents of the text widget will be stored under the old filename.
The code for this script is as follows and is placed in the file mes. It puts up a message widget which is created with the Tk command message with the message string passed as input. A "OK" button with the command to destroy this toplevel when the user clicks on the button is also included. Modal Interaction The Tk command toplevel creates a toplevel window for the application. The toplevel window is the child of the applications root main window but can be used as additional windows for the application.
Toplevel windows can also be used as popup message windows. In this case, in the procedure creating the popup message window, the Tk command grab with the name of the message window as argument is given. This will grab the keyboard focus to ensure user's attention. In the calling procedure, the Tk command tkwait window is called with the message window name as the argument. This suspends processing in the calling procedure, until the user undertakes the necessary interaction with the poppped up window and explicitly closes destroys it.
Note that the tagging is temporary and not saved in the file. Note that the the command "place" takes two options "-x" and "-y" whose values are integers pixels in this case and asks the packer to place the widget at that location inside the widget which is the value given for the option "-in". In this popup window the menubuttons Find and Find and Replace both have pulldown menus to make the search forward and back.
The procedures are defined in the next section. If you want to execute this script and test it, you can comment out the lines just before the -com option begins. This will stop the Tk interpreter complaining about undefined commands. If you wish you can create a separate script file procs. If you do, remember to source it from ed.
The selected file is stored in the global array "fileselect" at the associative index whose name is "selectedfile". The file is opened with read-only permission. The text editor ". The file is closed and the insertion cursor in the text window is placed at the first character of the first line. Tk Text Widget delete, insert and mark Recall that Tk creates a unique command ". The text widget specific actions can be invoked using this command. Special words such as "end", "lineend", marks the end of the displayed text or the end of a given line. The command. Note that ".
If it cannot open the file for any reason quits with the message that "No file name is given". Otherwise it writes the contents of the text widget into the file. If no new filename is given, the warning message is showed and the contents of the editor are not written. If the new filename is the same as the old one, then the warning that the file will be overwritten is displayed and the file will be overwritten by a call to "Savefile". If a new filename is given, the editor contents are written into this file.
Note that this binding is the default in the Tk text widget. The Tk command "selection get" takes a target as argument and retrieves the primary selection in the form specified by target. Tk supports only primary selection which means selection is owned in only one window on the screen. Cutselection assigns the retrieved selected text to the global variable "seltxt" for subsequent paste operation.
The widget command ". Note that the enclosure in "" is substituted and evaluated. In Tk text widget is a position specifier which returns a number of the form l. You can also specify index x,y which refers to the character closest to the pixel at position x,y in the window where x and y are integer values; index last refers to the last position in the line, first to first character in the line and index end point to end of the text. The Tcl command scan is similar to scanf in C. It takes as argument a string and a format and parses the string and assigns the elements to variables according to that format.
- From Elements to Atoms: A History of Chemical Composition.
- Neutrino Opacities in Nuclear Matter.
- Practical Programming In Tcl And Tk by Brent B. Welch?
- Buddhist Art Coloring Book 1: Auspicious Symbols and Mythical Motifs from the Tibetan Tradition!
In this procedure scan is given the current cursor position from which the current line is extracted and assigned to "cl". The Tk text widget action "search" takes a switch forward or backward , an option whether the search is exact or nocase , the string to search for and a serach range and returns the position if a match is found.
The primary selection is cleared in the selection buffer and it is no longer owned by the window when the call to "selection clear. If a match is found, the cursor is moved to that position and that position is brought within the visible region of the text widget by a call to ". All the tag names are registered in the name space and all occurances of the tagged text could be subsequently collectively referred to by their tag names. In this procedure wherever a match for a given string is found, it is tagged.
The string is used as the tag name e. You can display tagged text differently by calling ".
Note that any word or a phrase could have more than one tag associated with it too. It introduces some of the special features of Tk canvas widget such as embedded widgets and tagging names to displayed objects so that specific behaviour can be associated with them e. Tk canvas supports additional features such as Postscript output, scrolling, searching objects with a given property or closest to a given point , editable text and device indepentent coordinates also supports pixel based dimension specification.
You will need At this point it is assumed that the reader has read through the previous chapters. Scripts for creating buttons, scrollbars etc. Dish to Serve Up Part-I: Create a simple canvas based application to animate a text string when a button is pressed. When the user clicks the left mouse button over a country, its name should appear in an entry widget.
Alternatively, when the user enters a country name, ring a note and flash the region of the country. Part-I Place the script for all three steps of Part-I in animate. Part-II ssumed that you will place the script for all the three of the following into a single Tcl script file called EU.
The script is in the file eu. It also creates a button ". Embedded Widgets Some of the item types supported by Tk canvas are rectangle, ellipse, Bezier curve, bitmap and window. Canvas displays window for a widget at a given x,y position and provides the geometry management for the widget.
This allows for pre-packaged components with their own built-in functionality to be available alongside general drawing and hyper-linking capabilities of the canvas. If there are additional arguments to after beyond the time delay, then after concatenates the additional arguments into a script to be evaluated in the background after the given time delay and after returns immediately.
The return value of after is a unique command identifier of the delayed event. This identifier can be used to access the delayed command, to cancel it for instance. Then it reschedules itself to be invoked after the given time interval. The global variable "id" is assigned the return value from after each time after arranges for "movie" to be invoked. All three strings are assigned a single tag name "st". The command bell rings the display of the applications main window. You can give bell a -displayof option to specify the display of a particular window. Then "displayInfo" invokes the procedure "movie" with the tag name "st" and an interval milliseconds in this case as arguments.
The label on the button changes to "Stop". If the user clicks on the button, the label changes again to "The End" to mark the end of the animation. After an elapse of 10 seconds the button displays "Quit" for the user to click on to exit the application. The script included in this step generates a user interface that looks like: The code is self-explanatory.
Tcl/Tk and Expect
Note that it is useful to assign short variable names to long widget names e. Then the filled region is tagged with the country's name. The tag is associated with a binding for Button-1 left mouse button to show the coutry's name in the entry widget when the user clicks within the country's borders.
Experiment to see what happens when you click on the borders. The canvas widget specific command scale takes five arguments and rescales all the items identified by the tag given by the first argument. The second and third arguments are used as origins for the scaling operation and the fourth and fifth the scale factors in the x and y directions. This scaling operation is called repeatedly to display the data centred within the canvas widgets visible region.
The procedure "highLightCountry" takes the names of the canvas widget and the tag input via the entry widget. From this list the current colour of the tagged irtem is retrieved and assigned to old colour. The tagged region item is filled with the colour yellow. After 5 seconds, the old colour is reset. You can of course make the named country flash by rewriting this procedure to set and rest the old and new colours alternatively every so often. The procedure clearCanvas gets the list of all items displayed in the canvas and deletes them.
Scripts for creating pulldown menus, scrollbars etc. Dish to Serve Up Create a simple drawing editor. Recipe The script for this example draw. Remember to set the path to our wish binary properly. The bitmaps are part of the public domain xfig program.
The main frame contains three frame widgets - the frame ". Note that the height and width of the main frame as well as those of ". Tk canvas widget ". The scrollbars ". The menu entries for "File" is Print and Quit with associated actions printCanvas and exit; the menu entries for "Edit" are Cut and Clear with associated actions CutSelection and clearCanvas. Tk place command Note that for the horizontal scrollbar, the place rather than pack command is used with fixed size and location parameters to position slave widgets within their masters.
This allows for the slave to resize itself when the master changes size, preserving relative configuration. The first argument to image specifies the action to be taken e. The "-file" option rreads the bitmap data from the file specified. The "-image" option replaces the "-text" option in the button creation command to place the bitmap image as the labels for the buttons.
Each button command sets the value of the global variable "sb" to a specific value. The value of the variable is used in the cnavas drawing routines to determine which type of drawing primitive should be drawn. Text In this example, drawing text in the canvas is simplified. The user inputs the text string in the entry widget, hits return and selects the button marked "A".
Then the text string is created in the canvas wherever the left mouse button is clicked.source link
Practical Programming in Tcl and Tk, Fourth Edition
Selecting an Object The button with the "dotted rectangle" label is used to specify a rectangular region within the canvas widget. To mark this a rectangle will be drawn with a red outline. To do this, set the three bindings for the canvas: bind. If the chosen primitive is text, then the string item is drawn anchored southwest at current location specified by x,y values. If "sb" points to the "select an object", then a rectangle object is created with red outline and the variable "eo" is set to this rectangle's id to be used later to delete it selectively. A tag name made of concatenating the value of "sb" and the objects unique id is added using the widget command.
The procedure "KeepMoving" returns without doing anything if "sb" is "text" as it is not relevant in this case.
In all other cases, the widget command. The first argument to this action is the object id or tag. If no further arguments is specified, this action will return a list of the coordinates of the object. If "sb" is set to "obj" then the procedure "LetGo" invokes ". See what happens when you the selected item is a text string.
The procedure "clearCanvas" gets the display list of all items and deletes them one by one. In "printCanvas", the Tk canvas widget action postscript is invoked with a "-file" option. A postscript of the canvas contents will be saved in the file "canvas. Note that Tk will complain if you have no write permissions in the current working directory.
Item Tagging Tk canvas widget supports bindings for the canvas as well as bindings for individual items displayed within it. Each item created in the canvas has a unique id and it can also be associated with one or more tags. Item bindings can be associated with its bindings. For instance, you can move all items with a tag "rectangle" move a pixel left or right or change colour or fill them with a pattern. Item bindings preceed the canvas widget bindings. Experiment with these. Dish to Serve Up Create a simple Tk based graphical user interface with canvas widget.
Template The template for this script is tkAppInit. Make a copy of tkAppInit. Call it myTclInit. The Angle of rotation is input by the user by moving a Tk scale widget. This token is returned whenever a new Tk window is created. You can use this to query information about or manipulate a Tk window.
SetupPhigs is passed one argument - the pathname of the canvas widget. This "win" token is used to assign the necessary connection identifiers for the canvas widget to PHIGS. The third argument is the command procedure. The clientData is used to pass on address of objects associated with the command and deleteProc spoecifies the procedure to be invoked when the command is deleted.
It is used to free the object associated with the command as the clientData. In this example we have created five commands which can be used in the Tcl script which is parsed with this version of the Tcl interpreter. TV I just tried compiling it on a recent cygwin on XP, and it seems the AUX library from the older mesa is dropped, at least the include file isn't there.
Stochastic equations through the eye of the physicist basic concepts, exact results and asymptotic
I'll look into that, and try linux. TV : I had to squeeze in a new harddisk in a quite reasonable machine I can luckily use, and when transfering from the old one, I was stupid enough to let XP do its own installation stuff after I did a raw partition copy, with the old disk as second disk.
Neither XP nor cygwin have completely come around to my views on how everything from the partition numbering, registry info, OS dirs and of course PATH like environment vars should perfectly come together putting it mildly It works allright even unattended for weeks running a tclhttpd webserver , and the cygnus gnu gcc compiler isn't unuseable, but maybe it should be simply reinstalled as sort of a matter of principle I don't like to be forced to that to get flawless paths and everything.
Anyhow, I'm working on getting the thing back together. On the abovementioned page, ALL mesa libraries are available, I think also my adapted sources from that time, but recompiling that was fine 5 years ago, currently I think it is preferable to use the cygwin supplied libs and stubs to OS level openGL support.
Practical Programming in Tcl and Tk
I can use a fairly fast most recent RedHat linux capable machine, which I intend to use also for video graphics things, where the compiler, Xwindows with NVidea accelerator, and openGL are spinning now, which should also run the above example, I'll try it out, and maybe make a new version. How to embed Tcl in C applications. Chapter 44, C Programming and Tcl , is particularly relevant.
Cameron Laird's personal notes on how to use C with Tcl Points to several related tutorials. Richard Hipp Enormously simplifies for mere mortals the task of embedding Tk in programs written in C TES , by David Gravereaux Serves as a model for several of the more esoteric aspects of embedding an interpreter. It's the closest this Wiki apparently has, as of early July , to a minimal C application which invokes Tcl scripts. Simplified Wrapper And Interface Generator highlevel programming languages. No you can't have it, we plan on using it in yet another Tcl Book.
Course Prerequisites. Next Steps 4. Tcl Arrays Library Systems staff only. Course Prerequisites Some previous programming experience. Working knowledge of any Unix text editor emacs, vi, axe, etc. Emacs Tutorial On Tuesday 12 July , I will offer a tutorial introduction to the Emacs text editor to anyone who would like to attend. The first class will be 14 July The course will last approximately eight to ten weeks. On these two days we will meet in JRL This syllabus is subject to change, and depending on the speed at which the course progresses, we may not get to cover everything listed: in other words, we won't rush the course.
Please view corrections for Errata in the 4th edition. If you find an error not listed, please let me know. Buy the Book from Amazon.
Related Practical Programming in Tcl and Tk/Book and Disk
Copyright 2019 - All Right Reserved