Linux Penguin Guide
Linux Programming
- Tcl
- Tk+
I.
Tcl (Tool Command Language) and Tk
a.
Programming Tcl
Definition of Tcl : -
A simple, interpreted language
|
Type in the first Tk program, that displays a button, which on pressed,
exits :
xbutton.tk
[Kamran]
|
# Push-Button which Exits
button .b -text "Hello World" -command exit
pack .b
|
It is executed via
$ wish xbutton.tk (wish = `Windows Shell')
b.
Features of Tk
- wish :
$wish starts the window shell for Tk;
$tclsh starts the Tcl shell
- Root widget : . represents the root widget
-
Arguments and values :
- -text: argument the value of which is the String to display
- -command: command executed on pressing the button
xradiobutton.tk
[Kamran]
|
# Radiobutton and Checkbutton Demo
radiobutton .r -text "Fish" -command exit
checkbutton .c -text "Crab" -command exit
pack .r
pack .c
|
xmenubutton.tk
[Running.350]
|
frame .fr -relief groove -bd 3
menubutton .fr.mfile -text "File"
menubutton .fr.mobj -text "Object"
pack .fr -side top -expand yes -fill x
pack .fr.mfile .fr.mobj -side left
|
xmenu.tk
[Running.350]
|
frame .fr -relief groove -bd 3
menubutton .fr.mfile -text "File" -menu .fr.mfile.menu
menubutton .fr.mobj -text "Object" -menu .fr.mobj.menu
pack .fr -side top -expand yes -fill x
pack .fr.mfile .fr.mobj -side left
menu .fr.mfile.menu
.fr.mfile.menu add command -label "Quit" -command { exit }
menu .fr.mobj.menu
.fr.mobj.menu add radiobutton -label "Ovals" -command { exit }
.fr.mobj.menu add radiobutton -label "Rectangle" -command { exit }
|
The following program draws shapes to the canvas :
shapes.tk
[Running.347f]
|
frame .fr -relief groove -bd 3
set oval_count 0
set rect_count 0
set orig_x 0
set orig_y 0
proc set_oval {} {
global oval_count orig_x orig_y
# bind event to pressing mouse button 1 in the region .c ie. canvas
bind .c {
set orig_x %x
set orig_y %y
set oval_count [expr $oval_count + 1]
.c create oval %x %y %x %y -tags "oval$oval_count" -fill red
}
bind .c {
.c delete "oval$oval_count"
.c create oval $orig_x $orig_y %x %y -tags "oval$oval_count" -fill red
}
}
proc set_rect {} {
global orig_x orig_y
# bind event to pressing mouse button 1 in the region .c ie. canvas
bind .c {
set orig_x %x
set orig_y %y
set rect_count [expr $rect_count + 1]
.c create rectangle $orig_x $orig_y %x %y -tags "rec$rect_count" -fill blue
}
bind .c {
.c delete "rect$rect_count"
.c create rectangle $orig_x $orig_y %x %y -tags "rect$rect_count" -fill blue
}
}
menubutton .fr.mfile -text "File" -menu .fr.mfile.menu
menubutton .fr.mobj -text "Object" -menu .fr.mobj.menu
pack .fr -side top -expand yes -fill x
pack .fr.mfile .fr.mobj -side left
# create a menu
menu .fr.mfile.menu
.fr.mfile.menu add command -label "Quit" -command { exit }
canvas .c
pack .c -side top
menu .fr.mobj.menu
.fr.mobj.menu add radiobutton -label "Ovals" -command { set_oval }
.fr.mobj.menu add radiobutton -label "Rectangle" -command { set_rect }
|
xmenubutton.tk
[Running.350]
|
frame .fr -relief groove -bd 3
menubutton .fr.mfile -text "File" -menu .fr.mfile.menu
menubutton .fr.mobj -text "Object" -menu .fr.mobj.menu
pack .fr -side top -expand yes -fill x
pack .fr.mfile .fr.mobj -side left
menu .fr.mfile.menu
.fr.mfile.menu add command -label "Quit" -command { exit }
menu .fr.mobj.menu
.fr.mobj.menu add radiobutton -label "Ovals" -variable objtype \
-command { exit }
|
xentry.tk
[Running.343]
|
# Run with $wish FileEdit.tk
# Create label widget .l and entry widget .e
label .l -text "Filename : "
entry .e -relief sunken -width 30 -textvariable fname
# Place the widgets into the application window
pack .l -side left
pack .e -side left -padx 1m -pady 1m
# When return key is pressed, run xterm
bind .e {
exec xterm -e vi $fname
}
|
III.
Programming Languages
a.
Compilers
- perl
(`practical extraction and reporting language')
[ language ]
-
$perl p.pl
(perl compiler)
- java
(`java')
[ programming language ]
-
$javac f.java
(java compiler)
-
$java f
(java virtual machine)
- C
(`C')
[ programming language ]
-
$cc f.c
(C compiler)
-
$gcc f.c
(GNU C and C++ Compiler)
- Fortran
(`Formula Translation')
[ programming language ]
-
$f77 p.f
(Fortran 77 compiler)
-
$f90 p.f or
$fort90 p.f
(Fortran 90 Compiler)
b.
Mathematical Aids
- bc
(`best calculator')
[ arbitrary precision calculator using
scale, the number of decimal digits ]
- dc
(`desk calculator')
[ arbitrary precision calculator ]
References
-
`The Linux Programmer's Guide,'
Sven Goldt,
Sven van der Meer, Scott Burkett, Matt Welsh
http://linuxdoc.org/LDP/lpg/
- Running Linux Matt Welsh and Lar Kaufman,
O'Reilly and Asociates, Sebastopol, California USA 1995,
First edition.