Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Tcl/Tk 8.5 Programming Cookbook

You're reading from   Tcl/Tk 8.5 Programming Cookbook 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.

Arrow left icon
Product type Paperback
Published in Feb 2011
Publisher Packt
ISBN-13 9781849512985
Length 236 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (20) Chapters Close

Tcl/Tk 8.5 Programming Cookbook
Credits
About the Author
1. Acknowledgment
About the Reviewers
2. www.PacktPub.com
3. Preface
1. The Tcl Shell FREE CHAPTER 2. Using the Building Blocks Control Constructs 3. Error Handling 4. Handling String Expressions 5. Expanding String Functionality Using Lists 6. The Tcl Dictionary 7. File Operations 8. Tk GUI Programming with Tcl/Tk 9. Configuring and Controlling Tk Widgets 10. Geometry Management 11. Using Tcl Built-in Dialog Windows 12. Creating and Managing Menus 13. Creating the Address Book Application

Creating a simple form


As you can see this selection of widgets allows for a great deal of flexibility and provides enough features to address most of your GUI needs. To illustrate this we will now create a simple form.

How to do it…

In the following example, we will create a listbox with specific keywords and add items to the list programmatically. Using the text editor of your choice create a file named form.tcl containing the following text.

# Load the TK package
package require Tk
#Procedure to add to the listbox
proc list_add { } {
set s [ .e get ]
.l insert end $s
.e delete 0 end
}
# Create image and widgets
image create photo logo -file tcllogo.gif
label .logo -image logo
listbox .l -borderwidth 3 -width 25 -height 10
entry .e -width 25
frame .f -width 25 -borderwidth 2 -relief groove
button .f.update -text "Add" -command list_add
button .f.exit -text "Exit" -command exit
# Pack the widgets
pack .logo -side top -anchor w
pack .l -side top -anchor e
pack .f.update -side left
pack .f...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image