• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
Programming with VTK
11/12/2002
IPAG
1
November 12, 2002
Programming with VTK
Week 6: Tk and GUIs
Marcel Jackowski
mjack@noodle.med.yale.edu
http://noodle.med.yale.edu/tcl
http://www.tcl.tk/software/tcltk/8.4.html
November 12, 2002
2
VTK & Tcl/Tk Structure Overview
tclsh
tcl commands
libtcl8.4.so (tcl84.dll)
wish
tk commands
vtk
libtk8.4.so (tk84.dll)
November 12, 2002
3
What is Tk?
\u2022 A GUI toolkit implemented with Tcl and C;
\u2022 It runs on multiple platforms: X/ Motif,
Win32 GUI, Mac GUI;
\u2022 I t is a freely available open -source package
\u2022 Its simplicity enables fast development of
GUIs with far fewer lines of code;
\u2022 It allows for easy creation new GUI
controls;
\u2022 Used in commercial packages (e.g. Mayo
Clinic\u2019s Analyze)
November 12, 2002
4
How easy is to create a button?
November 12, 2002
5
Creating a button in X/Motif
1: #include <Xm/PushB.h>
2: int main(int argc, char *argv[])
3: {
4:
Widget toplevel, button;
5:
XtAppContext app;
6:
void button_pushed();
7:
XmString label;
8:
toplevel = XtVaAppInitialize(&app, \u201cHello\u201d, NULL, 0,
&argc, argv, NULL, NULL);
9:
label = XmStringCreateLocalized(argv[1]);
10:
button = XtVaCreateManagedWidgetClass(\u201cmybutton\u201d,
11:
xmPushButtonWidgetClass, toplevel,
12:
XmNlabelString, label,
13:
NULL);
14:
XmStringFree(label);
15:
XtAddCallback(button, XmNactivateCallback, button_pushed, NULL);
16:
XtRealizeWidget(toplevel);
17:
XtAppMainLoop(app );
18: }
19: void button_pushed(Widget widget, XtPointer clientdata, XtPointer calldata)
20: {
21:
printf(\u201cbutton pressed!\n\u201d);
22: }
November 12, 2002
6
Creating a button In Tcl/Tk
#!/bin/sh
# the next line is executed by the shell, but it is a comment in tcl \
exec wish \u201c$0\u201d \u201c$@\u201d
button . mybutton \u2013text [lindex $argv 0] \u2013command { puts \u201cbutton pressed!\u201d }
pack . mybutton
Programming with VTK
11/12/2002
IPAG
2
November 12, 2002
7
Elements in Tk programming
\u2022 Windows and Widgets
\u2022 Widgets: windows with a particular look
and feel
\u2022 Class commands: create different widgets
\u2022 Widget commands: configure widgets
\u2022 Geometry management commands: place,
pack & grid commands
\u2022 Event bindings
November 12, 2002
8
Widget classes
container widgets
regular widgets
November 12, 2002
9
The widget hierarchy
.
.menu.file
.scroll
.menu.help
.menu
.listbox
November 12, 2002
10
Types of windows
.menu.file
.scroll
.menu.help
.menu
.listbox
.dlg.no
.dlg.yes
.dlg.msg
.dlg
Main
window
Top-level
window
Internal
windows
.
November 12, 2002
11
Creating widgets
\u2022 Each widget has aclass: button, scrollbar,
listbox, etc;
\u2022 There\u2019s one class command for each class,
used to create instances:
button .a.b -text Quit -command exit
scrollbar .x -orient horizontal
class name
window name
configuration options
November 12, 2002
12
Configuration options
\u2022 Defined by each class. For buttons:
\u2022
-activebackground \u2013disabledforeground -justify
-underline
-activeforeground -font
-padx
-width
-anchor
-foreground
-pady
-wraplength
-background
-height
-relief
-bitmap
-highlightbackground -state
-borderwidth
-highlightcolor
-takefocus
-command
-highlightthickness -text
-cursor
-image
-textvariable
\u2022 If not specified in command line, take from
option database (option command);
\u2022 If not in option database, default provided
by class.
Programming with VTK
11/12/2002
IPAG
3
November 12, 2002
13
Widget commands
\u2022 Tcl command after each widget, named
after widget;
\u2022 Used to reconfigure, manipulate widget:
button .a.b \u2013text \u201cbutton\u201d
.a.b. configure \u2013relief sunken
listbox .a.l
.a.l insert end \u201cItem 1\u201d
.a.l selection clear 1 end
\u2022 Widget command is deleted after widget is
destroyed;
\u2022 Widget state should be readable and
modifiable anytime.
November 12, 2002
14
Geometry management
\u2022 Widgets don\u2019t control their own positions
and sizes: geometry managers do;
\u2022 They don\u2019t even appear on screen until
managed by a geometry manager;
\u2022 Geometry manager = algorithm for
arranging slave windows relative to a
master window
\u2022 Three geometry managers: packer, placer
and gridder
November 12, 2002
15
The \u201cplace\u201d command
\u2022 Each slave placed individually relative to its
master:
(b) place .x -rely 0.4 -relx 1.0 -anchor ne
(c) place .x -rely 0.4 -relx 1.0 -anchor c
(a) place .x -x 0 -y 0
(a)
(b)
(c)
(b)
= anchor point
November 12, 2002
16
The \u201cplace\u201d command
place .x -relwidth .5 -relheight .5
place .x -relwidth .5 -relheight .5 -relx .5 -rely .5
place .x -relwidth .5 -relheight .5 -relx .5 -rely .5 -anchor c
November 12, 2002
17
The \u201cpack\u201d command
\u2022 Packs slaves around edges of master\u2019s cavity:
pack .dismiss-side bottom
pack .sep -side bottom
pack .icon -side left
pack .mesg -side right
November 12, 2002
18
The \u201cpack\u201d command
pack .dismiss -side bottom- pady 4
pack .sep- fill x -pady 4
.mesg configure-f o n t Courier20
pack .icon -side left- padx 8 -pady 8
pack .mesg -side right -padx 8 -pady 8
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...