Tcl/Tk 8.5 Programming Cookbook

Book description

With over 100 recipes, this Cookbook is ideal for both beginners and advanced Tcl/Tk programmers. From the basics to creating applications, it’s full of indispensable tips and tricks to make the most of the language.

  • The quickest way to solve your problems with Tcl/Tk 8.5
  • Understand the basics and fundamentals of the Tcl/Tk 8.5 programming language
  • Learn graphical User Interface development with the Tcl/Tk 8.5 Widget set
  • Get a thorough and detailed understanding of the concepts with a real-world address book application
  • Each recipe is a carefully organized sequence of instructions to efficiently learn the features and capabilities of the Tcl/Tk 8.5 language

In Detail

With Tcl/Tk, you can create full-featured cross-platform applications in a simple and easy-to-understand way without any expensive development package; the only tools required are a simple text editor and your imagination. This practical cookbook will help you to efficiently interact with editors, debuggers, and shell type interactive programs using Tcl/Tk 8. This cookbook will comprehensively guide you through practical implementation of Tcl/Tk 8.5 commands and tools.

This book will take you through all the steps needed to become a productive programmer in Tcl/Tk 8. Right from guiding you through the basics to creating a stand-alone application, it provides complete explanation of all the steps along with handy tips and tricks.

The book begins with an introduction to the Tcl shell, syntax, variables, and programming best practices in the language. It then explores procedures and the flow of events with control constructs followed by advanced error trapping and recovery. From Chapter 4, a detailed study of string expressions and handling enables you to handle various string functions and use lists to expand the string functionality. The book then discusses in-depth the Tcl Dictionary and how to utilize it to store and retrieve data. File operations and Tk GUI handling are covered extensively along with a developing a real-world address book application to practice the concepts learned.

A practical, comprehensive cookbook to master the depths and breadths of Tcl/Tk 8.5 programming

Table of contents

  1. Tcl/Tk 8.5 Programming Cookbook
    1. Table of Contents
    2. Copyright
    3. Credits
    4. About the Author
    5. Acknowledgment
    6. About the Reviewers
    7. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Errata
        2. Piracy
        3. Questions
    9. 1. The Tcl Shell
      1. Introduction
      2. The Tcl shell
      3. Writing to the Tcl console
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Mathematical expressions
      5. Tcl expr operands
      6. Mathematical functions
      7. Computing mathematical expressions
      8. Referencing files in Tcl
        1. UNIX (UNIX, Linux and Mac OS X)
        2. Windows
      9. Variables
        1. Basic variable commands
        2. Getting Ready
        3. How to do it…
        4. How it works…
        5. There's more…
          1. Unsetting a variable
      10. Command line arguments
        1. Launching a Tcl script
        2. Getting Ready
        3. How to do it…
        4. How it works…
        5. There's more…
    10. 2. Using the Building Blocks Control Constructs
      1. Introduction
      2. Controlling flow with the if statement
        1. How to do it…
        2. How it works…
        3. There's more…
      3. Looping with for
        1. How to do it…
        2. How it works…
      4. Looping with foreach
        1. How to do it…
        2. How it works…
      5. Looping with while
        1. How to do it…
        2. How it works…
      6. Continuing a procedure
        1. How to do it…
        2. How it works…
      7. Breaking out of a procedure
        1. How to do it…
        2. How it works…
      8. Nested looping
        1. How to do it…
        2. How it works…
        3. There's more…
    11. 3. Error Handling
      1. Introduction
      2. Using the catch command
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Using the eval command
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      4. Using the error command
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Error handling procedure
        1. Getting ready
        2. How to do it…
        3. How it works…
    12. 4. Handling String Expressions
      1. Introduction
      2. Appending to a string
        1. How to do it…
        2. How it works…
      3. Formatting a string
        1. How to do it…
        2. How it works…
      4. Matching a regular expression within a string
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Performing character substitution on a string
        1. How to do it…
        2. How it works…
      6. Parsing a string using conversion specifiers
        1. How to do it…
        2. How it works…
      7. Determining the length of a string
        1. How to do it…
        2. How it works…
      8. Comparing strings
        1. Getting ready
        2. How to do it…
        3. How it works…
      9. Comparing a string of characters
        1. How to do it…
        2. How it works…
      10. Locating the first instance of a character
        1. How to do it…
        2. How it works…
      11. Locating the index of a character
        1. How to do it…
        2. How it works…
      12. Determining the class of a string
        1. How to do it…
        2. How it works…
      13. Locating the last instance of a string
        1. How to do it…
        2. How it works…
      14. Determining the size of a string
        1. How to do it…
        2. How it works…
      15. Replacing values within a string
        1. How to do it…
        2. How it works…
      16. Locating a pattern within a string
        1. How to do it…
        2. How it works…
      17. Returning a range of characters from a string
        1. How to do it…
        2. How it works…
      18. Creating a string of repeated characters
        1. How to do it…
        2. How it works…
      19. Replacing ranges of characters contained within a string
        1. How to do it…
        2. How it works…
      20. Creating a reverse string
        1. Getting ready
        2. How to do it…
        3. How it works…
      21. Converting a string to lowercase
        1. How to do it…
        2. How it works…
      22. Converting a string to title
        1. How to do it…
        2. How it works…
      23. Converting a string to uppercase
        1. How to do it…
        2. How it works…
      24. Trimming a string
        1. How to do it…
        2. How it works…
      25. Trimming leading whitespace
        1. How to do it…
        2. How it works…
      26. Trimming trailing whitespace
        1. How to do it…
        2. How it works…
      27. Locating the word end
        1. How to do it…
        2. How it works…
      28. Locating the word start
        1. How to do it…
        2. How it works…
      29. Performing variable substitution
        1. How to do it…
        2. How it works…
    13. 5. Expanding String Functionality Using Lists
      1. Introduction
      2. Creating a list
        1. How to do it…
        2. How it works…
        3. There's more…
      3. Joining two lists
        1. How to do it…
        2. How it works…
        3. There's more…
      4. Joining list elements
        1. How to do it…
        2. How it works…
        3. There's more…
      5. Appending list elements
        1. How to do it…
        2. How it works…
      6. Assigning list elements to variables
        1. How to do it…
        2. How it works…
      7. Retrieving an element from a list
        1. How to do it…
        2. How it works…
      8. Inserting elements into a list
        1. How to do it…
        2. How it works…
      9. Determining the number of elements
        1. How to do it…
        2. How it works…
      10. Getting a list element
        1. How to do it…
        2. How it works…
      11. Repeating elements
        1. How to do it…
        2. How it works…
        3. There's more…
      12. Replacing elements
        1. How to do it…
        2. How it works…
      13. Reversing elements
        1. How to do it…
        2. How it works…
      14. Searching a list
        1. How to do it…
        2. How it works…
      15. Editing a list
        1. How to do it…
        2. How it works…
      16. Sorting a list
        1. How to do it…
        2. How it works…
      17. Splitting a string into a list
        1. How to do it…
        2. How it works…
    14. 6. The Tcl Dictionary
      1. Introduction
      2. Creating a dictionary
        1. How to do it…
        2. How it works…
        3. There's more…
          1. Using set with the dict create command
      3. Appending to a dictionary
        1. How to do it…
        2. How it works…
      4. Determining if a key exists
        1. How to do it…
        2. How it works…
      5. Filtering a dictionary
        1. How to do it…
        2. How it works…
        3. There's more…
      6. Searching a dictionary
        1. How to do it…
        2. How it works…
      7. Getting a record
        1. How to do it…
        2. How it works…
      8. Incrementing a value
        1. How to do it…
        2. How it works…
      9. Getting the dictionary structure
        1. How to do it…
        2. How it works…
      10. Getting a list of keys
        1. How to do it…
        2. How it works…
      11. Appending to an existing record
        1. How to do it…
        2. How it works…
      12. Merging two dictionaries
        1. How to do it…
        2. How it works…
      13. Creating a blank dictionary structure
        1. How to do it…
        2. How it works…
      14. Updating variables from a dictionary
        1. How to do it…
        2. How it works…
      15. Determining the size of a dictionary
        1. How to do it…
        2. How it works…
      16. Getting all records
        1. How to do it…
        2. How it works…
      17. Assigning values
        1. How to do it…
    15. 7. File Operations
      1. Introduction
      2. Opening a file
        1. How to do it…
        2. How it works…
        3. There's more…
      3. Configuring a file
        1. How to do it…
        2. There's more…
      4. Opening a command pipeline
        1. How to do it…
        2. How it works…
        3. There's more…
      5. Writing a file
        1. How to do it…
        2. How it works…
      6. Reading a file
        1. How to do it…
        2. How it works…
      7. Closing a file
        1. How to do it…
        2. How it works…
      8. File handling
        1. Getting ready
        2. How to do it…
        3. How it works…
    16. 8. Tk GUI Programming with Tcl/Tk
      1. Introduction
      2. Creating a widget
        1. How to do it…
        2. How it works…
        3. There's more…
      3. Writing to the console
        1. How to do it…
        2. How it works…
      4. Setting the attributes of the window through window manager
        1. How to do it…
        2. How it works…
      5. Creating an additional window
        1. Standard options:
        2. Window-specific options
        3. Commands
          1. How to do it…
          2. How it works…
        4. Destroying a window
          1. How to do it…
          2. How it works…
          3. There's more…
        5. Creating a custom dialog
          1. How to do it…
          2. How it works…
    17. 9. Configuring and Controlling Tk Widgets
      1. Introduction
      2. Creating a frame widget
        1. How to do it…
        2. How it works…
      3. Creating a label widget
        1. How to do it…
        2. How it works…
      4. Creating an entry widget
        1. How to do it…
        2. How it works…
      5. Creating a button widget
        1. How to do it…
        2. How it works…
      6. Creating a listbox widget
        1. How to do it…
        2. How it works…
      7. Creating an image
        1. Getting ready
        2. How to do it…
        3. How it works…
      8. Creating a simple form
        1. How to do it…
        2. How it works…
    18. 10. Geometry Management
      1. Introduction
      2. Controlling layout with the pack command
        1. How to do it...
        2. How it works…
      3. Controlling layout with the grid command
        1. How to do it…
        2. How it works…
      4. Combining pack and grid
        1. How to do it…
        2. How it works…
      5. Creating an address book interface
        1. Getting ready
        2. How to do it…
        3. How it works…
    19. 11. Using Tcl Built-in Dialog Windows
      1. Introduction
      2. Displaying a message box
        1. How to do it…
        2. How it works…
      3. Displaying a confirmation dialog
        1. How to do it…
        2. How it works…
      4. Displaying the color picker
        1. How to do it…
        2. How it works…
      5. Displaying the directory dialog
        1. How to do it…
        2. How it works…
      6. Displaying the file selection dialog
        1. How to do it…
        2. How it works…
      7. Selecting a directory and file
        1. How to do it…
        2. How it works…
    20. 12. Creating and Managing Menus
      1. Introduction
      2. Creating a menu
        1. How to do it…
        2. How it works…
      3. Adding menu buttons
        1. How to do it…
        2. How it works…
      4. Displaying a pop-up menu
        1. How to do it…
        2. How it works…
      5. Data entry application
        1. How to do it…
        2. How it works…
    21. 13. Creating the Address Book Application
      1. Introduction
      2. Creating the Address Book application
        1. How to do it…
        2. How it works…
      3. Adding a record
        1. How to do it…
        2. How it works…
      4. Navigating records
        1. How to do it…
        2. How it works…
      5. Deleting a record
        1. How to do it…
        2. How it works…
      6. Finding a record
        1. How to do it…
        2. How it works…
      7. Full listing
    22. Index

Product information

  • Title: Tcl/Tk 8.5 Programming Cookbook
  • Author(s): Bert Wheeler
  • Release date: February 2011
  • Publisher(s): Packt Publishing
  • ISBN: 9781849512985