%include "default.mgp" %deffont "std1" tfont "timesbd.ttf" %deffont "standard" tfont "timesbd.ttf" %deffont "thick" tfont "timesbd.ttf" %deffont "typewriter" tfont "courbd.ttf" %default 4 font "std1", fore "yellow" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %pcache 1 1 1 50 %nodefault %bgrad 0 0 32 0 0 "grey98" "grey98" "grey98" "grey98" "grey98" "grey98" "grey98" "grey98" "grey98" "grey98" "#000000222" %fore "red", size 7, font "standard" %center %IMAGE "lug-meppen-logo.jpg" %size 2, center, fore "darkblue" Ein kurzer Einblick in Tcl/Tk %font "standard" %size 2, fore "red", font "thick" LUG Meppen %size 2, font "typewriter" Alexander Spanke Alexander.Spanke@ewetel.net %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %back "#000000222" %size 2 Was ist Tcl? Was ist Tk? %fore "red" T %cont, fore "yellow" ool %cont, fore "red" C %cont, fore "yellow" ommand %cont, fore "red" L %cont, fore "yellow" anguage Interpretierende Programmiersprache Basiert haupstächlich auf Kommandos tclsh ( %cont, font "typewriter", fore "white" /usr/bin/tclsh %cont, font "standard", fore "yellow" ) interpretiert Tcl Kommandos Erste Zeile in Tcl-Skripten: %cont, font "typewriter", fore "white" #!/usr/bin/tclsh %font "standard", fore "yellow" Erweiterbar durch C und C++ API Die Bearbeitung von Listen ist ein besonderes Merkmal von Tcl %fore "red" T %cont, fore "yellow" ool %cont, fore "red" K %cont, fore "yellow" it Basiert auf Tcl Zur Erstellung von graphischen Oberflächen wish ( %cont, font "typewriter", fore "white" /usr/bin/wish %cont, font "standard", fore "yellow" ) interpretiert Tk Kommandos Erste Zeile in Tk-Skripten: %cont, font "typewriter", fore "white" #!/usr/bin/wish %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %back "#000000222" Variablen und Wertzuweisung %font "typewriter", fore "white" set %cont, font "standard", fore "yellow" weist einer Variablen einen Wert zu. Z.B. %cont, font "typewriter", fore "white" set a Hallo $ %cont, font "standard", fore "yellow" wertet die Variable aus. Z.B. %cont, font "typewriter", fore "white" puts $a %font "standard", fore "yellow" Arrays sind spezielle Arten von Variablen. Z.B. %cont, font "typewriter", fore "white" set xx(2) MMM; set xx(Otto) 37; puts $xx(Otto) %font "standard", fore "yellow" Mit dem %cont, font "typewriter", fore "white" array %cont, font "standard", fore "yellow" Befehl sind weitere Bearbeitungen von Arrays möglich. %font "typewriter", fore "white" set VARIABLE [BEFEHL] %cont, font "standard", fore "yellow" speichert das Ergebnis von BEFEHL in der Variablen VARIABLE Innerhalb von %cont, font "typewriter", fore "white" "" %cont, font "standard", fore "yellow" werden Variablen und %cont, font "typewriter", fore "white" [] %cont, font "standard", fore "yellow" -Ausdrücke ausgewertet Innerhalb von %cont, font "typewriter", fore "white" {} %cont, font "standard", fore "yellow" werden Variablen und %cont, font "typewriter", fore "white" [] %cont, font "standard", fore "yellow" -Ausdrücke NICHT ausgewertet %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %back "#000000222" Kommandos Tcl/Tk hat kaum Syntax. Viele Programmstrukturen werden durch Kommandos abgebildet. Z.B. %cont, font "typewriter", fore "white" if %cont, font "standard", fore "yellow" oder %cont, font "typewriter", fore "white" while %font "standard", fore "yellow" Kommandos bestehen aus Listen von einem oder mehreren Worten Das erste Wort ist das eigentliche Kommando, die folgenden Worte sind zusätzliche Argumente. %font "standard", fore "yellow" Worte werden durch Leerzeichen getrennt oder müssen in %cont, font "typewriter", fore "white" "" %cont, font "standard", fore "yellow" oder %cont, font "typewriter", fore "white" {} %cont, font "standard", fore "yellow" eingeschlossen sein. Das %cont, font "typewriter", fore "white" proc %cont, font "standard", fore "yellow" Kommando erzeugt neue Befehle. Es hat 3 Argumente: %cont, fore "red" Kommandoname Argumente und Body %font "typewriter", fore "white" proc summe {val1 val2} { return [expr $val1 + $val2] } %font "typewriter", fore "white" return %cont, font "standard", fore "yellow" erlaubt es, Werte aus einem mit %cont, font "typewriter", fore "white" proc %cont, font "standard", fore "yellow" erzeugten Kommando zurück zu liefern. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %back "#000000222" Einige builtin Kommandos %font "typewriter", fore "white" puts WORT %cont, font "standard", fore "yellow" gibt "WORT" auf der Konsole aus %font "typewriter", fore "white" if BEDINGING BODY1 else BODY2 %cont, font "standard", fore "yellow" If-Bedingung mit (optionalem) Else-Zweig %font "typewriter", fore "white" for START TEST NEXT BODY %cont, font "standard", fore "yellow" Schleife mit Startwert, Prüfung und Wertänderung %font "typewriter", fore "white" foreach VARIABLE LISTE BODY %cont, font "standard", fore "yellow" Schleife über Elemente einer Liste %font "typewriter", fore "white" lindex LISTE INDEX %cont, font "standard", fore "yellow" Liefert das INDEX-te Element der Liste %font "typewriter", fore "white" lsearch LIST PATTERN %cont, font "standard", fore "yellow" Durchsucht LISTE nach dem Muster PATTERN und liefert den Index des ersten Treffers %font "typewriter", fore "white" lsort LISTE %cont, font "standard", fore "yellow" Liefert sortierte Liste %font "typewriter", fore "white" lappend VARIABLE ELEM1 ELEM2 ELEM3 ... %cont, font "standard", fore "yellow" Fügt Elemente ELEM1 ELEM2 ELEM3 ... einer Liste der Variablen VARIABLE hinzu %font "typewriter", fore "white" exec SHELLBEFEHL ARG1 ARG2 ... %cont, font "standard", fore "yellow" Führt einen Shell-Befehl aus %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %page %back "#000000222" Wichtige Tk Widgets %font "typewriter", fore "white" label %cont, font "standard", fore "yellow" Label Widget %font "typewriter", fore "white" entry %cont, font "standard", fore "yellow" Widget zur eingabe von texten %font "typewriter", fore "white" frame %cont, font "standard", fore "yellow" Frame Widget, das als Container für andere Widgets dient %font "typewriter", fore "white" listbox %cont, font "standard", fore "yellow" Listen Widget %font "typewriter", fore "white" checkbutton %cont, font "standard", fore "yellow" Ja/Nein Checkbox %font "typewriter", fore "white" button %cont, font "standard", fore "yellow" Normale Schaltfläche %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%