Building User Interfaces With Tcl And Tk John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part III.

Slides:



Advertisements
Similar presentations
Chapter 9 Working with Tabs and Tables. Chapter Objectives Work with tabs Create and format a table Format text in a table Place graphics in a table.
Advertisements

MS® PowerPoint.
Tk. Toolkit n Wish - windowing shell –touch fileName –chmod +x fileName –xedit fileName & –#!/usr/local/bin/wish n Widgets - eg Buttons, Labels, Frames.
Tk Widgets This material is best on several sources –Slides by Dr. Ernest J. Friedman-Hill –various Tcl/Tk books.
Module Word 2007 Basics Learning Outcomes Learn basic Word 2007 commands. Create, save, and print documents. Apply text, paragraph, and page formats. Review.
PowerPoint. Getting Started with PowerPoint Objectives Start PowerPoint and open presentations Explore toolbars and menus Use the Office Assistant Work.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Tcl/Tk 1 CS 414, Software Engineering I Mark Ardis Rose-Hulman Institute December 3, 2002.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Building User Interfaces with Tk/Tcl Outline –Basic Structures –Widget Creation –Geometry Management –Widget Commands –Event Bindings –Interprocess Communication.
Tcl and Tk CSE 470 Fall 1999 Revised by Prasad. Objective To use Tcl Tk to develop GUI and prototype of the project.
Introduction To Form Builder
1 Chapter 5: Introduction To Form Builder. 2 Forms  Why Do We Use Form Builder?  Why Don’t We Use SQL Only?!
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 9 Margins and Print.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
Lesson No:9 MS-Word Tools, Mail Merge and working with Tables CHBT-01 Basic Micro process & Computer Operation.
© Paradigm Publishing, Inc Access 2010 Level 2 Unit 1Advanced Tables, Relationships, Queries, and Forms Chapter 4Creating and Using Custom Forms.
IC 3 BASICS, Internet and Computing Core Certification Key Applications Lesson 10 Creating and Formatting an Excel Worksheet.
Chapter 3: Using GUI Objects and the Visual Studio IDE.
Tcl/Tk: An introduction D. Kim, K. Kundu, and M. Siegel November 26, 2002 CMSC 631.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Beginning PowerPoint Part 1 The Basics. PowerPoint startup options: AutoContent Wizard Design Template * Blank presentation Open an existing presentation.
Windows Tutorial Common Objects ACOS: 1, 4. Using the Taskbar 1. Using the taskbar, you can switch between open programs and between open documents within.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Interaction Models II Marti Hearst (UCB SIMS) SIMS 213, UI Design & Development March 11, 1999.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management Brad Myers Advanced User Interface Software 1© 2013.
PERL TK. 4.Use an IDE 3. Use the documentation! 2. Experiment. 1.Learn the basics.
GISMO/GEBndPlan Overview Geographic Information System Mapping Object.
Using Advanced Options Lesson 14 © 2014, John Wiley & Sons, Inc.Microsoft Official Academic Course, Microsoft Word Microsoft Word 2013.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
9-Nov-97Tri-Ada '971 TASH An Alternative to the Windows API TRI-Ada ‘97 Terry J. Westley
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
Lesson 6 Formatting Cells and Ranges. Objectives:  Insert and delete cells  Manually format cell contents  Copy cell formatting with the Format Painter.
Microsoft Access Intro Class 9 Report Design.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
JDS5 Training Guide. On Start Up you will see this screen click the OK button Click OK.
Video in Macromedia Flash (Optional) – Lesson 121 Video in Macromedia Flash (Optional) Lesson 12.
Introducing Dreamweaver. Dreamweaver The web development application used to create web pages Part of the Adobe creative suite.
Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective.
Microsoft FrontPage 2003 Illustrated Complete Creating a Frames Page.
Change margins. 1 Preview a document. 2 Change paper size and orientation. 3 Print envelopes and labels. 4 Choose print options. 5 2.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
Laboratory Exercise # 10 – Microsoft Word Additional Topics Office Productivity Tools 1 Laboratory Exercise # 10 Microsoft Word Additional Topics Objectives:
CIS 205—Web Design & Development Flash Chapter 3 Working with Symbols and Interactivity.
COMPSA Exam Prep Session by Paul Allison On: April 8th from 1:30-3:00 Location TBA Winter 2016CISC101 - Prof. McLeod1.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Change margins. 1 Preview a document. 2 Change paper size and orientation. 3 Print envelopes and labels. 4 Choose print options. 5 2.
1 Chapter 6: Creating Oracle Data Block Forms. 2 Forms  Application with a graphical user interface that looks like a paper form  Used to insert, update,
Programming Using Tcl/Tk Week 3 Seree Chinodom
An Introduction To Tcl Scripting John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part II.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
Fundamentals of Windows Mouse n 4 Basic Operations: –Pointing –Clicking –Double Clicking –Dragging.
Creating LOVs and Editors
Chapter 1: An Introduction to Visual Basic 2015
Building a User Interface with Forms
Program and Graphical User Interface Design
GUI Using Python.
Program and Graphical User Interface Design
TCL/TK Tool Command Language/Tool Kit.
This Week: Tkinter for GUI Interfaces Some examples
Presentation transcript:

Building User Interfaces With Tcl And Tk John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part III

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 2 Outline u Basic structures: windows, widgets, processes. u Creating widgets: class commands. u Widget commands. u Geometry management: the placer and the packer. u Bindings. u Other commands: send, focus, selection, window manager, grabs.  Two examples: showVars, mkDialog.

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 3 Structure Of A Tk Application u Widget hierarchy. u One Tcl interpreter. u One process (can have > 1 application in a process). u Widget: a window with a particular look and feel. u Widget classes implemented by Tk: FrameMenubuttonCanvas LabelMenuScrollbar ButtonMessageScale CheckbuttonEntryListbox RadiobuttonTextToplevel

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 4 The Widget Hierarchy..menu.file.scroll.menu.help.menu.listbox

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 5 Types Of Windows.menu.file.scroll.menu.help.menu.listbox.dlg.no.dlg.yes.dlg.msg.dlg Main window Top-level window Internal windows.

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 6 Creating Widgets u Each widget has a class: button, listbox, scrollbar, etc. u 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

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 7 Configuration Options u Defined by class. For buttons: -activebackground-disabledforeground-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 u If not specified in command, taken from option database: –Loaded from RESOURCE_MANAGER property or.Xdefaults file. –May be set, queried with option command. u If not in option database, default provided by class.

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 8 Widget Commands u Tcl command for each widget, named after widget. u Used to reconfigure, manipulate widget: button.a.b.a.b configure -relief sunken.a.b flash scrollbar.x.x set x get u Widget command is deleted when widget is destroyed. u Principle: all state should be readable, modifiable, anytime.

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 9 Geometry Management u Widgets don't control their own positions and sizes: geometry managers do. u Widgets don't even appear on the screen until managed by a geometry manager. u Geometry manager = algorithm for arranging slave windows relative to a master window. Geometry Manager Requested size from slave Parameters from application designer Geometry of master Size and location of slave Requested size for master

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 10 The Placer u Simple but not very powerful. u Each slave placed individually relative to its master. place.x -x 0 -y 0 place.x -x 1.0c -rely 0.5 -anchor w

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 11 The Placer, cont'd place.x -relx 0.5 -rely 0.5 \ -height 2c -anchor center place.x -relheight 0.5 \ -relwidth 0.5 -relx 0 -rely 0.5

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 12 The Packer u More powerful than the placer. u Arranges groups of slaves together (packing list). u Packs slaves around edges of master's cavity. u For each slave, in order: 1. Pick side of cavity. 2.Slice off parcel for slave. 4.Position slave in parcel. 3.Optionally grow slave to fill parcel.

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 13 The Packer: Choosing Sides button.ok -text OK button.cancel -text Cancel button.help -text Help pack.ok.cancel.help -side left.cancel configure -text "Cancel Command" pack.ok.cancel.help -side top

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 14 The Packer: Padding pack.ok.cancel.help -side left \ -padx 2m -pady 1m pack.ok.cancel.help -side left \ -ipadx 2m -ipady 1m pack.ok.cancel.help -side left \ -padx 2m -pady 1m -ipadx 2m -ipady 1m

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 15 The Packer: Filling Stretch widgets to fill parcels: pack.ok.cancel.help -side top pack.ok.cancel.help -side top -fill x

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 16 The Packer: Filling, cont'd pack.menu -side top pack.scrollbar -side right pack.listbox pack.menu -side top -fill x pack.scrollbar -side right -fill y pack.listbox

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 17 The Packer: Expansion Increase parcel size to absorb extra space in master: pack.ok.cancel.help -side left pack.ok.cancel -side left pack.help -side left \ -expand true -fill x pack.ok.cancel -side left pack.help -side left -expand true

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 18 The Packer: Expansion, cont'd pack.ok.cancel.help -side left \ -expand true pack.ok.cancel.help -side left \ -expand 1 -fill both

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 19 Hierarchical Packing Use additional frames to create more complex arrangements: frame.left pack.left -side left -padx 3m -pady 3m frame.right pack.right -side right -padx 3m -pady 3m foreach size { } { radiobutton.pts$size -variable pts \ -value $size -text "$size points" } pack.pts8.pts10.pts12.pts18.pts24 \ -in.left -side top -anchor w checkbutton.bold -text Bold \ -variable bold checkbutton.italic -text Italic \ -variable italic checkbutton.underline -text Underline \ -variable underline pack.bold.italic.underline \ -in.right -side top -anchor w

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 20 Connections u How to make widgets work together with application, other widgets? Tcl scripts. u Widget actions are Tcl commands: button.a.b -command exit u Widgets use Tcl commands to communicate with each other: scrollbar.s -command ".text yview" u Application uses widget commands to communicate with widgets. exit button release.text yview scroll 1 unit click on arrow

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 21 Bindings u Associate Tcl scripts with X events: bind.b {backspace.t} u Use tags to select one or more windows: –Name of window:.b –Widget class: Text –All windows: all –Arbitrary string: foo, bar,... Window(s)EventScript

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 22 Bindings: Specifying Events u Specifying events: a Modifiers Event Type Button or Keysym

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 23 Bindings: Substitutions u % substitutions in binding scripts: –Coordinates from event: %x and %y. –Window: %W. –Character from event: %A. –Many more... u Examples: bind.c {move %x %y} bind.t {insert %A} bind all {help %W}

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 24 Binding Order u What if multiple bindings match an event? bind.t a... bind all... u One binding triggers per tag: most specific.  Default order of tags: widget, class, toplevel, all.  Can change tags with bindtags command: bindtags.b {MyButton.b foo all}  Can use break to skip later tags. u Note: these rules apply only to Tk 4.0.

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 25 More On Bindings u Text and canvas widgets support bindings internally: –Associate tags with text or graphics:.t tag add foo c create rect 1c 1c 2c 2c -tags foo –Associate bindings with tags:.t bind foo {...}.c bind foo {...} u Bindings always execute at global level: –If binding created in procedure, procedure's local variables aren't available at event-time.

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 26 Quoting Hell u Often want binding script to use some information from binding-time, some from event-time. u Use list commands to generate scripts. u Use procedures to separate event-time information from bind-time information. bind.x {set y [expr $a + $b]} bind.x "set y [expr $a + $b]" proc sety a { global b y set y [expr $a + $b] } bind.x [list sety $a] Use bind-time valueUse event-time valueWrong Right

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 27 Other Tk Commands u The selection: selection get selection get FILE_NAME u Issuing commands to other Tk applications: send tgdb "break tkEval.c:200" winfo interps н wish tgdb ppres u Window information: winfo width.x winfo children. winfo containing $x $y

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 28 Access To Other X Facilities u Keyboard focus: focus.x.y u Communication with window manager: wm title. "Editing main.c" wm geometry. 300x200 wm iconify. u Deleting windows: destroy.x u Grabs: grab.x grab release.x

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 29 Example #1: showVars u Displays values of one or more values, updates automatically: showVars.vars name age ssn phone

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 30 showVars, cont'd proc showVars {w args} { toplevel $w wm title $w "Variable values" frame $w.menu -relief raised -bd 2 pack $w.menu -side top -fill x menubutton $w.menu.file -text File \ -menu $w.menu.file.m -underline 0 pack $w.menu.file -side left menu $w.menu.file.m $w.menu.file.m add command -label Quit \ -command "destroy $w" -underline 0... }

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 31 showVars, cont'd proc showVars {w args} {... frame $w.bot -relief raised -bd 2 pack $w.bot -side bottom -fill both label $w.bot.title -width 20 -anchor center \ -text "Variable values:" -font \ -Adobe-Helvetica-Medium-r-normal--*-180-*-*-*-*-*-*- pack $w.bot.title -side top -fill x... }

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 32 showVars, cont'd proc showVars {w args} {... foreach i $args { frame $w.bot.$i pack $w.bot.$i -side top -anchor w label $w.bot.$i.name -text "$i: " label $w.bot.$i.value -textvariable $i pack $w.bot.$i.name -side left pack $w.bot.$i.value -side left } showVars.vars name age ssn phone

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 33 Example #2: mkDialog Creates dialog box, waits until button pressed, returns index. mkdialog.d "File Modified" $msg warning \ "Save File" "Discard Changes" "Return To Editor" Window NameTitleMessageBitmap Button Labels

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 34 mkDialog, cont'd proc mkDialog {w title text bitmap args} { toplevel $w wm title $w $title wm protocol $w WM_DELETE_WINDOW { } frame $w.top -relief raised -bd 1 pack $w.top -side top -fill both frame $w.bot -relief raised -bd 1 pack $w.bot -side bottom -fill both label $w.msg -wraplength 3i -text $text \ -justify left -font \ -Adobe-Times-Medium-R-Normal--*-180-*-*-*-*-*-* pack $w.msg -in $w.top -side right \ -expand 1 -fill both -padx 3m -pady 3m... }

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 35 mkDialog, cont'd proc mkdialog {w title text bitmap args} {... if {$bitmap != ""} { label $w.bitmap -bitmap $bitmap pack $w.bitmap -in $w.top -side left \ -padx 3m -pady 3m }... }

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 36 mkDialog, cont'd proc mkDialog {w title text bitmap args} {... set i 0 foreach but $args { button $w.button$i -text $but \ -command "set button $i" pack $w.button$i -in $w.bot -side left \ -expand 1 -padx 3m -pady 2m incr i }... }

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 37 mkDialog, cont'd proc mkDialog {w title text bitmap args} { global button... grab $w set oldFocus [focus] focus $w tkwait variable button destroy $w focus $oldFocus return $button }

Tcl/Tk Tutorial Part III: Tk ScriptingDecember 12, 1995, slide 38 Summary u Creating interfaces with Tk is easy: –Create widgets. –Arrange with geometry managers. –Connect to application, each other. u Power from single scripting language: –For specifying user interface. –For widgets to invoke application. –For widgets to communicate with each other. –For communicating with outside world. –For changing anything dynamically.