TCL/TK Tool Command Language/Tool Kit.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Tcl and Otcl Tutorial Part I Internet Computing KUT Youn-Hee Han.
Programming Using Tcl/Tk These slides are based upon u several Tcl/Tk text books u material byDr. Ernest J. Friedman-Hill.
ISBN Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl –(on reserve.
NS-2 LAB: TCL Semester A Miriam Allalouf.
Writing Tcl Scripts (cont.) Outline –Variable Scoping –Strings –Eval –File/Channel I/O –Processes –System Info –Errors –Reflection/Debugging –Libraries.
Tcl and Tk CSE 470 Fall 1999 Revised by Prasad. Objective To use Tcl Tk to develop GUI and prototype of the project.
Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl Linux editors and commands (e.g.
Writing Tcl Scripts Outline Goal Reading Syntax Data Types
Tcl/Tk 2 CS 414, Software Engineering I Mark Ardis Rose-Hulman Institute December 5, 2002.
Characters and Strings. Characters In Java, a char is a primitive type that can hold one single character A character can be: –A letter or digit –A punctuation.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Chapter 2 Software Tools and Assembly Language Syntax.
Innovation Intelligence ® 1 Chapter 1: Introduction to TCL.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Tcl/TK Tutorial. 2 Learning Tcl/TK What is Tcl/TK? –An interpreted programming language Build on-the-fly commands, procedures Platform-independent Easy.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
CS 330 Programming Languages 10 / 02 / 2007 Instructor: Michael Eckmann.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Programming Using Tcl/Tk Week 2 Seree Chinodom
TCL TK. Tcl/Tk C functions can become Tcl commands that are invoked interactively Tk = scriptable, portable user interface –Windows, X (Unix), MacOS,
Introduction to Tcl/Tk TraNese Christy U.S. Army Research Laboratory.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Dongsoo S. Kim  Tcl: Tool Command Language Interpreted programming (scripting) language Build on-the-fly commands and procedures Embeddable.
1 Lecture 10 Introduction to AWK COP 3344 Introduction to UNIX.
Scripting.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
17-Mar-16 Characters and Strings. 2 Characters In Java, a char is a primitive type that can hold one single character A character can be: A letter or.
Shell scripts – part 1 Cs 302. Shell scripts  What is Shell Script? “Shell Script is series of command written in plain text file. “  Why to Write Shell.
Tcl/Tk Part 2.
An Introduction To Tcl Scripting John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part II.
TCL/TK Tool Command Language/Tool Kit. What is TCL? u Tool Command Language u An interpreted programming language  Created by John Ousterhout.John Ousterhout.
Perl & TCL Vijay Subramanian, Modified from : perl_basics_06.ppt.
COMP075 OS2 Bash Scripting. Scripting? BASH provides access to OS functions, like any OS shell Also like any OS shell, BASH includes the ability to write.
Lecture 3: Getting Started & Input / Output (I/O)
C++ First Steps.
Definition of the Programming Language CPRL
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
Chapter 6 JavaScript: Introduction to Scripting
Introduction to C++ Programming
Basic Elements of C++.
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Introduction to Scripting
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
Programming Using Tcl Maxwell Created By: Quan Nguyen Created Date: 12/12/2016 TCL Training1.
Basic Elements of C++ Chapter 2.
John Carelli, Instructor Kutztown University
This Week: Tkinter for GUI Interfaces Some examples
Statements, Comments & Simple Arithmetic
NS-2 LAB: TCL Miriam Allalouf Semester A.
Introduction to C++ Programming
Introduction to C++ Programming
C Programming Getting started Variables Basic C operators Conditionals
Introduction to Java Applications
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
12th Computer Science – Unit 5
Presentation transcript:

TCL/TK Tool Command Language/Tool Kit

What is Tcl/Tk? Tcl a scripting language can be extended in C (but this is harder) ugly but simple Tk a simple but powerful widget set Hello World: a complete program that exits when a person presses the button grid [ button .myButton -text "Hello World" -command exit ] Simple things are simple, hard things are possible

Tcl features Tcl supports a lot of functions for string processing list processing arrays (key–value pairs) processing It also supports error trapping, sockets, namespaces, packages and all that.

Scripts and Commands Tcl script = Sequence of commands. Commands separated by newlines, semi-colons. Tcl command = One or more words separated by white space. First word is command name, others are arguments. Returns string result. Example: set myName Saul

Variable Substitution Syntax: $varName Variable name is letters, digits, underscores. May occur anywhere in a word. Sample command Result set b 66 66 set a b b set a $b 66 set a $b+$b+$b 66+66+66 set a $b.3 66.3 set a $b4 no such variable

Command Substitution Syntax: [script] Evaluate script, substitute result. May occur anywhere within a word. Sample command Result set b 8 8 set a [expr $b+2] 10 set a "b-3 is [expr $b-3]" b-3 is 5

Controlling Word Structure Words break at white space and semi-colons, except: Double-quotes prevent breaks: set x 4; set y 5 set a "x is $x; y is $y" -> x is 4; y is 5 Curly braces prevent breaks and substitutions: set a {[expr $b*$c]} ->[expr $b*$c] Backslashes quote special characters: set a word\ with\ \$\ and\ space ->word with $ and space

Controlling Word Structure (continued) Substitutions don't change word structure: set a "two words" set b $a -> two words

Comments The # is the comment command Tcl parsing rules apply to comments as well set a 22; set b 33 <- OK # this is a comment <- OK set a 22 # same thing? <- Wrong! set a 22 ;# same thing <- OK

Summary of Tcl Command Syntax Command: words separated by whitespace First word is a function, others are arguments Only functions apply meanings to arguments Single-pass tokenizing and substitution $ causes variable interpolation [ ] causes command interpolation “” prevents word breaks { } prevents all interpolation \ escapes special characters

String Manipulation String manipulation commands: regexp format split string regsub scan join string subcommands compare first last index length match range toupper tolower trim trimleft trimright Note: all indexes start with 0. end means last char string tolower "THIS" ;# this string trimleft “XXXXHello” ;# Hello string index “abcde” 2 ;# c

Control Structures C-like in appearance. Just commands that take Tcl scripts as arguments. Commands: if for switch break foreach while eval continue

if else set x 2 if {$x < 3} { puts "x is less than 3" } else { puts "x is 3 or more" }

Procedures proc command defines a procedure: proc decrement {x} { expr $x-1 } Procedures behave just like built-in commands: decrement 3 í 2 Arguments can have default values: proc decrement {x {y 1}} { expr $x-$y decrement 100 5 ;# 95 decrement 100 ;# 99 name body list of argument names

Procedures Procedures can have a variable number of arguments proc sum args { set s 0 foreach i $args { incr s $i } return $s } sum 1 2 3 4 5 í 15 sum í 0

Example FACTORIAL WITH PROCEDURES proc factorial n { if {$n <= 0} { return 1 } else { return [expr {$n * [factorial [expr {$n - 1}]]}] }

TK widgets To create a widget, you invoke a command named after the widget’s class: button for button widgets, scrollbar for scrollbar widgets, and so on.. For example, the following command creates a button that displays the text “Press me” in red: button .b -text "Press me" -foreground red The widget name is followed by any number of pairs of arguments, where the first argument of each pair specifies the name of a configuration option for the widget (e.g. -text or -foreground) and the second argument specifies a value for that option (e.g. “Press me” or red).

With wish you can make a widget appear by invoking the pack command with the widget’s name as argument. For example, the following script creates a button widget and displays it on the screen: button .b -text "Hello, world!" pack .b This will size the main window so that it is just large enough to hold the button and it will arrange the button so that it fills the space of the main window.

Tcl/Tk applications TkDVI is a DVI previewer built with the Tcl/Tk toolkit. http://tkdvi.sourceforge.net/ TkVNC is a VNC viewer written in pure Tcl/Tk. It is designed to be embedded inside other applications, but can be used as a standalone VNC viewer. http://www.ifost.org.au/Software/tkvnc/index.html Xpvm is a TCL/TK based tool that allows full manageability of the PVM cluster as well as the ability to monitor cluster performance. http://www.csm.ornl.gov/pvm/