Вы находитесь на странице: 1из 5

Tcl/Tk

3 days
70% Lecture/30% Lab
Basic Level

Overview
Tcl (Tool Command Language) is a remarkably simple scripting language that’s easy to
learn, yet powerful enough to implement large-scale, distributed applications. Whether you
need to build a complex graphical user interface, create a network-enabled application, or
develop a cross-platform program, Tcl can help you get the job done in less time than you
thought possible. Additionally, the language’s support for Internet access, database access,
and internationalization, as well as its stability and robustness, make it well-suited for
enterprise-wide applications.
The Tk extension to Tcl allows you to add a full-featured GUI to your application that will
have a platform-native appearance on Windows, Unix, and Macintosh. This Tcl extension
has proven so popular that it’s been ported as the standard GUI library for other scripting
languages such as Perl and Python.

Benefits
From this course you will learn
• Basic Tcl/Tk syntax and commands for writing Tcl/Tk scripts
• String processing, data structure manipulation, basic process interaction and file
handling
• How to make applications run faster
• How to create clean, maintainable code
• How to use basic Tk interface components and how to modify and extend their
behaviors and put them together into complex applications
• Some advanced features of Tcl/Tk

Note: Included in this course are optional advanced Tk modules covering topics including:
the text widget; the canvas widget; menus; and multi-window applications. Depending on
course pacing, student experience, and student needs, course delivery can be customized to
include these modules as needed.

TM Associates, Inc ● www.tm-associates.com ● 503-656-4457


Intended Audience
This course is recommended for people with a basic programming background who need to
gain a working understanding of Tcl/Tk for extracting and manipulating data.

Prerequisites
Students need to be familiar with the basics of programming and the use of a text editor.
Although Tcl/Tk can run on a number of operating systems, the course is normally taught in
a UNIX/Linux or Windows environment; student need to be familiar with basic file system
use (file system navigation; creating/opening files; etc.).

Suggested Follow-On Course:

Interprocess Communication with Tcl


Exploring Expect

Training Approach
This is an intensive, interactive course, which is approximately 70% lecture and 30% lab.
Questions are highly encouraged. On the final day, students are given access to a zipped file
containing all of the solutions to the labs and the examples used throughout the course.

Course Outline
• Using “incr” for Integer Arithmetic
Day 1
Module 3 — Quoting and
Introduction to Tcl Programming, Substitution Rules
Part 1 • Quoting with Quotes Vs. Braces
• Nested Quoting Characters
Module 1 — Introduction to Tcl • Commands Substitution
• A Brief History of Tcl
• Tcl Resources Module 4 — Math
• The Tcl Interpreters—tclsh and wish • Arithmetic Operators and Functions
• Basic Tcl Syntax • Integer vs. Floating-Point Arithmetic
• Executing Tcl Commands Exercise 2
Interactively • Boolean Expressions
• Using “source” to Execute Tcl Scripts • String Comparisons

Module 2 — Variables Module 5 — String Manipulation


• Creating and Changing Variables • Concatenating Strings
• Variables Substitution: Getting • Counting Characters
Variable Values • Extracting Characters from Strings
Exercise 1 • Finding Substrings
• Simulating Pointers in Tcl Exercise 3
• Numerical Values in Tcl • Changing String Capitalization

TM Associates, Inc ● www.tm-associates.com ● 503-656-4457


• “Safe” String Comparisons
• Formatting Strings Day 2
• Parsing Strings
Exercise 4 Introduction to Tcl Programming,
Part 2
Module 6 — Looping and
Conditional Execution Module 10 — Arrays
• Conditional Execution with “if” • What’s an Array?
• Conditional Execution with “switch” • Creating Array Elements
• Looping with “while” and “for” • Getting Array Values
• Exiting Loops with “break” • Deleting Arrays and Array Elements
• Skipping Code with “continue” • Getting Information about Arrays
• Proper Coding Style • Processing Arrays and Element of the
Exercise 5 Time
• Converting between Arrays and Lists
Module 7 — Procedures • Multidimensional Arrays
• Defining Procedures • Complex Data Structures
• Variable Scope
• Giving Procedures Access to the Module 11 — Advanced Procedures
Global Scope • “Pass-by-Reference” with “upvar”
• Returning Values from Procedures Lab 3
Lab 1 • Default Values for Procedure
Arguments
Module 8 — Error Handling • Variable Argument-Length Procedures
• What Happens When an Error Occurs? Lab 4
• Analyzing a Stack Trace • Using “eval” to Process Argument
• Intentionally Generating an Error Structure
• Gracefully Recovering from Errors
Lab 2 Module 12 — Accessing the
Environment
Module 9 — Lists • Working with Times and Dates
• What’s a List? • Accessing Environment Variables
• Creating Lists • Predefined Global Variables
• Merging Lists • Self-Executing Scripts
• Processing List Elements with • Accessing Script Arguments
“foreach”
• Extracting List Elements Module 13 — Files
• Sorting Lists • Cross-Platform Pathname
• Editing Lists Manipulation
• Converting between Strings and Lists • Accessing Directories Using “glob”
Lab 3 • Manipulating Files and Directories
• Performing Timing Experiments • Getting File Attributes
Lab 5
• Opening Files for Reading and Writing
• Reading and Writing Files
TM Associates, Inc ● www.tm-associates.com ● 503-656-4457
• Closing Files
• Buffering Issues Module 3 — Basic Tk Widgets
• Terminal Input/Output • Using Widgets
Lab 6 • Tcl Variables with Tk Widgets
• More on the Event Loop
Module 14 — Processes • Checkbuttons
• Executing Processes with “exec” • Radiobuttons
• Process Pipelines • Entries
• Detecting Error Conditions • Spinboxes
• Widget State
Module 15 — A Survey of Popular • Listboxes
Extensions Lab 1
• Obtaining Extensions
• Using Extensions (the “package” Module 4 — Laying Out Displays
Command) with the Pack
• Descriptions of Popular Extensions • Displaying Scrollbars
• How pack Arranges Widgets
Day 3 • Positioning a Widget in its Packing
Space
Building Graphical User Interfaces • Resizing a Widget in its Packing Space
with Tk • Enlarging the Window
• Packing Space vs. Widget Size
Module 1 — Introduction to Tk
• Expanding Widgets into the Extra
• What is Tk? Packing Space
• Running the wish Interpreter • Strategies for Shrinking Windows
• What's a Widget? • Creating and Using Frames
• How do You Create Widgets? Lab 2
• The wish Version of “Hello World”
• The Event Loop Module 5 — Laying Out Displays
• Treating Tk as a Package with the Grid
• Laying Out Displays with grid
Module 2 — Working with Widgets • Using grid for Regular, Row/Column
• Widget Attributes Layouts
• Widgets as Objects • Empty Grid Cells
• Configuration Options • More Complex Grids
• Configuring Colors • Spanning Cells in a Grid
• Configuring Position • Aligning and Filling Widgets with grid
• Configuring Text • Resizable Grids
• Configuring the Border Lab 3
• Displaying Bitmaps • Combining pack and grid
• Displaying Images
Module 6 — Events
• Creating Images
Exercise 1 • Overview of Events
• A Typical Sequence of Events

TM Associates, Inc ● www.tm-associates.com ● 503-656-4457


• Event Types • Index Arithmetic
• Basic Event Binding • Common Text Widget Attributes
• Event Specification Syntax • Inserting Text
• Event Matching–The “Best Match” • Deleting and Retrieving Text
Algorithm • Tab Stops
• Event Substitutions • Tagging Text
• Class Bindings • Manipulating Text Tags
• Event Propagation • Configuring Tag Attributes
• Binding Tags • Character-Formatting Tag Attributes
Lab 4 • Line-Formatting Tag Attributes
• Using Bindings for Interactive
Module 7 (Optional) — The Canvas Displays
Widget
• Text Manipulation through Tags
• A Simple Sketchpad
• Drawing on a Canvas Module 9 (Optional) — Top-Level
• Drawing Complex Pictures Windows and Dialogs
• Manipulating Canvas Items • Creating, Using, and Destroying Top-
• Searching for Canvas Items Level Windows
• Tagging Canvas Items • Custom Dialogs: Show/Hide Approach
• Using Canvas Tags Lab 6
• Using Bindings for Interactive • Built-In Dialogs
Displays
• Cross-Platform Coding Module 10 (Optional) — Creating
• Conflicting Canvas Bindings and Using Menus
• “Masking” Conflicting Bindings • Adding a Menu Bar to a Window
• Scrolling a Canvas • Adding Menu Items
• The Canvas “Viewport” • Adding “Alt Key” Accelerators
• Screen Coordinates vs Canvas • Adding “Control Key” Accelerators
Coordinates • Tear-Off Menus
Lab 5 • Pop-Up Menus
• Menu Buttons
Module 8 (Optional) — The Text • Option Menus
Widget Lab 7
• Identifying Positions in a Text Widget

For more information, contact

Tom Wille
tw@tm-associates.com
503-656-4457

TM Associates, Inc ● www.tm-associates.com ● 503-656-4457

Вам также может понравиться