Introduction to Tcl and Tk Outline –The Tcl Language –The Tk Toolkit –Tk Applications –Composing Applications –Status and Conclusions Goal –Understand.

Slides:



Advertisements
Similar presentations
Tk Widgets This material is best on several sources –Slides by Dr. Ernest J. Friedman-Hill –various Tcl/Tk books.
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
LAB 3 NS2 Preliminaries. Contents TCL/OTCl Fundamentals Creating Network Setting Connections Generating Traffic Inserting Errors Configuring for multicast.
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Writing Tcl Scripts (cont.) Outline –Variable Scoping –Strings –Eval –File/Channel I/O –Processes –System Info –Errors –Reflection/Debugging –Libraries.
Executable XML Present by 吳昆澤. Outline  Introduction  Simkin  Jelly  o:XML  Conclusion.
Programming for Image Processing/Analysis and Visualization using The Visualization Toolkit Week 2: An Introduction to Tcl Xenios Papademetris
Building User Interfaces with Tk/Tcl Outline –Basic Structures –Widget Creation –Geometry Management –Widget Commands –Event Bindings –Interprocess Communication.
Tcl and Tk CSE 470 Fall 1999 Revised by Prasad. Objective To use Tcl Tk to develop GUI and prototype of the project.
Scripting Languages CS351 – Programming Paradigms.
Writing Tcl Scripts Outline Goal Reading Syntax Data Types
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures Modified from the text book.
The Basic Tools Presented by: Robert E., & Jonathan Chase.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
1 Outline 7.1 Introduction 7.2 Implementing a Time Abstract Data Type with a Class 7.3 Special Attributes 7.4Controlling Access to Attributes 7.4.1Get.
1 Chapter 20 — Creating Web Projects Microsoft Visual Basic.NET, Introduction to Programming.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
Computer Software.
1 Introduction to Human Computer Interaction  Livecode Overview  Based on Livecode User Guide from RunRev Ltd. (2010) 
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
CTEC 1863 – Operating Systems Shell Scripting. CTEC F2 Overview How shell works Command line parameters –Shift command Variables –Including.
An Overview of Tcl and Tk John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part I.
1 Programming Concepts Module Code : CMV6107 Class Contact Hours: 45 hours (Lecture 15 hours) (Laboratory/Tutorial 30 hours) Module Value: 1 Textbook:
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
4 - 1 Copyright © 2006, The McGraw-Hill Companies, Inc. All rights reserved.
Introduction to NS2 -Network Simulator- -Prepared by Changyong Jung.
An Introduction to Unix Shell Scripting
Computer Science 111 Fundamentals of Programming I Overview of Programming.
CHAPTER FOUR COMPUTER SOFTWARE.
Why Java? A brief introduction to Java and its features Prepared by Mithat Konar.
Tcl/Tk: An introduction D. Kim, K. Kundu, and M. Siegel November 26, 2002 CMSC 631.
BLU-ICE and the Distributed Control System Constraints for Software Development Strategies Timothy M. McPhillips Stanford Synchrotron Radiation Laboratory.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
Ch 1. A Python Q&A Session Spring Why do people use Python? Software quality Developer productivity Program portability Support libraries Component.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
FLUKA GUI Status FLUKA Meeting CERN, 10/7/2006.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Eagle: Maturation and Evolution 17th Annual Tcl Conference Joe Mistachkin.
Univ. of TehranDistributed Operating Systems1 Advanced Operating Systems University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
C Language: Introduction
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
Chapter Three The UNIX Editors.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Reading Flash. Training target: Read the following reading materials and use the reading skills mentioned in the passages above. You may also choose some.
Programming Using Tcl/Tk
9-Nov-97Tri-Ada '971 TASH An Alternative to the Windows API TRI-Ada ‘97 Terry J. Westley
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.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
An Overview of Tcl/Tk Programming. Tcl/Tk Tcl (Tool Command Language) is used by over half a million developers worldwide and has become a critical component.
Scripting.
Introduction  Program: Set of sequence instruction that tell the computer what to do.  Software: A collection of programs, data, and information. 
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Introduction to ASP.NET development. Background ASP released in 1996 ASP supported for a minimum 10 years from Windows 8 release ASP.Net 1.0 released.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
 Wind River Systems, Inc Chapter - 4 CrossWind.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing.
An Introduction To Tcl Scripting John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part II.
CST 1101 Problem Solving Using Computers
TCL/TK Tool Command Language/Tool Kit.
This Week: Tkinter for GUI Interfaces Some examples
Intro to PHP.
Presentation transcript:

Introduction to Tcl and Tk Outline –The Tcl Language –The Tk Toolkit –Tk Applications –Composing Applications –Status and Conclusions Goal –Understand basics of Tcl and Tk –Understand Tk/Tcl philosophy Reading –Ch. 5-9, Practical Programming in Tcl and Tk

Overview What –Tcl: embeddable scripting language –Tk: X11/Windows/Mac toolkit and widgets based on Tcl Principle –single interpretive language controls all aspects of all interactive applications »function »interface »composition of pieces »communication between applications Results –higher- level graphics programming - simpler, 10X faster –greater power - more programmable, programs work together

Tcl: Tool Command Language Problem –interactive programs need command languages –traditionally redone for each application –result: weak, quirky –Emacs and csh nice, but cannot reuse Solution: Tcl –command language = embeddable C library –powerful features: procedures, variables, lists, expressions, loops, etc. –extensible by applications

Language Philosophy Language classes –large application implementation (structure, performance important) –scripting, extensions –interactive commands (structure bad, performance not critical) One language can’t meet all three needs? Tcl goals –simple syntax (for humans) –programmable –easy to interpret –simple interface to C/C++ procedures C Tcl

Tcl Syntax Basic syntax like shells –words separated by spaces: cmd arg arg arg... –commands separated by newlines, semicolons –commands return string results Simple substitution rules –variables: set a $b –command results: set a [expr $b+2] –complex arguments: if $a<0 { puts stdout “a is negative” }

More on the Tcl Language Rich set of built-in commands –variables, associative arrays, lists –arithmetic expressions –conditionals, looping –procedures –access to files, system commands Only data type is string –easy access from C/C++ –programs and data are interchangeable

Example: Factorial proc fac x { if {$x<=1} { return 1 } expr {$x*[fac [expr $x-1]]} } fac 4 Returns: 24

Embedding Tcl in Applications Parser Init Command Loop Application generates Tcl scripts Tcl parses scripts, calls command procedures with argc, argv Application extends built-in command set –define new object types in C –implement primitive operations on objects as new Tcl commands –build complex features with Tcl scripts TclApplication Built-In CommandsApplication Commands

The Tk Toolkit Problem –too hard to build applications with nice user interfaces Wrong Solution –C++, object-oriented toolkits –only 10-20% improvement, must still program at low level Right Solution –raise the level of GUI programming –create interfaces by writing Tcl scripts

Creating Interfaces with Tk Widgets/windows have path names.dlg.quit Create widget with command named after class button.dlg.quit -text Quit \ -foreground red -command exit Tell geometry manager where to display widget place.dlg.quit -x 0 -y 0 pack.dlg.quit -side bottom

Other Tk Features Manipulate widgets with widget commands.dlg.quit flash.dlg.quit configure -relief sunken Use Tcl for interconnection –buttons, menu entries invoke Tcl commands –scrollbars and listboxes communicate with Tcl –can define new event bindings in Tcl –selection, focus accessible via Tcl Tk also provides C interfaces –create new widget classes –create new geometry managers

What’s a Tk-Based Application? 1. The Tcl interpreter 2. The Tk toolkit 3. Application-specific C code (primitives!) –new object types –new widgets 4. Tcl scripts (compose primitives) –build GUI –respond to events Tcl commands

Wish: Simplest Tk Application Wish - windowing shell No C code except command-line reader Can build many apps as wish scripts –Hello, world: label.hello \ -text “Hello, world”.pack.hello –simple directory browser »30 lines of Tk/Tcl

Browser Wish Script listbox.list -yscroll “.scroll set” \ -relief raised -width 20 -height 20 pack.list -side left scrollbar.scroll -command “.list yview” pack.scroll -side right -fill y if {$argc > 0} { set dir [lindex $argv 0] } else { set dir “.” } foreach i [exec ls -a $dir] {.list insert end $i } bind.list { browse $dir [selection get] } bind.list {destroy.} focus.list

Browse Script Cont. proc browse {dir file} { global env if {$dir != “.”} {set file $dir/$file} if [file isdirectory $file] { exec browse $file & } else { if [file isfile $file] { exec $env(EDITOR) $file & } else { puts stdout “can’t browse $file” } Browse is also name of wish script

TkSol - Tk-Based Solitaire Program

TkSol Statistics Code –1635 lines of Tk/Tcl code –4 card down bitmaps –52 card up bitmaps (4 suits of 13 cards each) –almost all time in bitmap creation Comparison to MS Solitaire –simpler end game –has auto-play mode –slower startup –slower deal –similar interactive speed

TkMines Statistics Code –1178 lines of Tk/Tcl code –uses a few signal and time commands from TclX extension, are not really needed –several small bitmaps for squares Comparison to MS Mines –simpler score file –same look-and-feel –slower startup –similar interactive performance

Composing Applications Problem –only communication between applications is via selection »OLE on MS Windows provides object selection –result: monolithic programs Solution - send command –send appName command –any Tk application can invoke anything in any other Tk application: interface or actions –result: powerful communication –result: big security hole

Composing Applications, cont. Examples –debugger - sends command to editor to highlight line of execution –UI editor - sends commands to modify interface of live application –multimedia - send record, play commands to audio and video applications –spreadsheets - cell sends commands to database to fetch current value Revolutionary results –build complex systems as collections of specialized but reusable hypertools –easy to create active objects: embeddable Tcl commands. Hypertext, hypermedia is easy.

Status Source and documentation freely available –developed at UC Berkeley –now maintained and developed at Sun Labs –code redistributable in commercial applications –runs on UNIX, Windows, Mac Large user/developer community –50,000+ worldwide –comp.lang.tcl newsgroup –many commercial products –several books Many extensions available –Tk is just one extension

Drawbacks Must learn new language –substitution can be confusing Interpreted language has performance limits –want a compiler for some applications –want to avoid C programming –dynamic compiler will provide at least 10x speedup Competition –Visual Basic –AppleScript –Java/JavaScript

Conclusions High-level programming –less to learn –easy to learn –build applications very quickly One interpretive language for everything –extend and modify applications at run-time –make many things work together Web programming/agent language? –platform independent –interpreted –easily embedded –secure