Building User Interfaces with Tk/Tcl Outline –Basic Structures –Widget Creation –Geometry Management –Widget Commands –Event Bindings –Interprocess Communication.

Slides:



Advertisements
Similar presentations
MS® PowerPoint.
Advertisements

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.
Formulas, Functions, Formatting, and Web Queries
What is a Dialog box? A Dialog box is a window or “form” that contains other child windows or “controls” that have a specific appearances and pre-defined.
Chapter 5 Multitable Forms
Creating a Document with a Table, Chart, and Watermark
Microsoft Office 2010 Access Chapter 1 Creating and Using a Database.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Introduction to Tcl and Tk Outline –The Tcl Language –The Tk Toolkit –Tk Applications –Composing Applications –Status and Conclusions Goal –Understand.
Introduction To Form Builder
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
Chapter 3 Working with Symbols and Interactivity.
Dreamweaver CS4 Concepts and Techniques Chapter 7 Page Layout with Frames.
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
Web Technologies Website Development Trade & Industrial Education
© Paradigm Publishing, Inc Access 2010 Level 2 Unit 1Advanced Tables, Relationships, Queries, and Forms Chapter 4Creating and Using Custom Forms.
Creating a Web Site to Gather Data and Conduct Research.
Microsoft Expression Web-Illustrated Unit I: Working with Tables.
IC 3 BASICS, Internet and Computing Core Certification Key Applications Lesson 10 Creating and Formatting an Excel Worksheet.
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
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.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Dreamweaver CS4 Concepts and Techniques Chapter 2 Adding Web Pages, Links, and Images.
Key Applications Module Lesson 21 — Access Essentials
Creating Buttons – Lesson 51 Creating Buttons Lesson 5.
Interaction Models II Marti Hearst (UCB SIMS) SIMS 213, UI Design & Development March 11, 1999.
Chapter 5 Quick Links Slide 2 Performance Objectives Understanding Framesets and Frames Creating Framesets and Frames Selecting Framesets and Frames Using.
Building User Interfaces With Tcl And Tk John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part III.
Microsoft PowerPoint Tutorial Created by L. George 2006.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Designer Basics.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
PERL TK. 4.Use an IDE 3. Use the documentation! 2. Experiment. 1.Learn the basics.
Chapter 4 Working with Frames. Align and distribute objects on a page Stack and layer objects Work with graphics frames Work with text frames Chapter.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 9 GUI Programming Using Tkinter 1.
Microsoft Access 2000 Presentation 3 Creating Databases Part II (Creating Forms)
9-Nov-97Tri-Ada '971 TASH An Alternative to the Windows API TRI-Ada ‘97 Terry J. Westley
Creating visual interfaces in python
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.
© 2011 Delmar, Cengage Learning Chapter 4 Working with Frames.
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,
Introduction to Drafting and Design In order to begin our drawing we have to set the drawing limits or the paper size.
Video in Macromedia Flash (Optional) – Lesson 121 Video in Macromedia Flash (Optional) Lesson 12.
Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective.
Creating and Editing a Web Page
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
Programming Using Tcl/Tk Week 4 Seree Chinodom
Access Queries and Forms. Adding a New Field  To insert a field after you have saved your table, open Access, and open the table  It is easier to add.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
CIS 205—Web Design & Development Flash Chapter 3 Working with Symbols and Interactivity.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
COMPSA Exam Prep Session by Paul Allison On: April 8th from 1:30-3:00 Location TBA Winter 2016CISC101 - Prof. McLeod1.
Programming Using Tcl/Tk Week 3 Seree Chinodom
1 Pertemuan 10 Using Type Matakuliah: U0344 / DESKTOP 1 Tahun: 2006.
Chapter 11 Enhancing an Online Form and Using Macros Microsoft Word 2013.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
Chapter 1: An Introduction to Visual Basic 2015
Building a User Interface with Forms
GUI Using Python.
Fundamentals of Python: From First Programs Through Data Structures
This Week: Tkinter for GUI Interfaces Some examples
Chapter 2 – Introduction to the Visual Studio .NET IDE
Introduction to PowerPoint
Topics Graphical User Interfaces Using the tkinter Module
Presentation transcript:

Building User Interfaces with Tk/Tcl Outline –Basic Structures –Widget Creation –Geometry Management –Widget Commands –Event Bindings –Interprocess Communication –Misc. Commands –Examples Goal –Understand Tk syntax –Understand Tk built-in commands Reading –Ch , Practical Programming in Tcl and Tk

Structure of a Tk Application 1. Widget hierarchy 2. One Tcl interpreter 3. One process –can have > 1 application in a process Widget = window with particular look and feel Widget classes implemented by Tk –frame, toplevel –label, button, checkbutton, radiobutton –menu, menubutton –message, dialog –entry, text, listbox –canvas –scrollbar, scale

The Widget Hierarchy..listbox.menu.scroll.menu.file.menu.help

Types of Windows Main window Top-level window Internal windows.listbox..menu.scroll.menu.file.menu.help.dlg.dlg.msg.dlg.yes.dlg.no

Creating Widgets Each widget has a class: button, listbox, etc. Tcl command named after each class, used to create instances button.a.b -text Quit -command exit scrollbar.x -orient horizontal class name window name configuration options

Configuration Options Defined by class –for buttons: activeBackground, activeForeground, anchor, background, bitmap, borderWidth, command, cursor, disableForeground, font, foreground, height, padx, pady, relief, state, text, textVariable, width If not specified on command line, taken from option database –loaded from RESOURCE_MANAGER property or.Xdefault s file –may be set, queried with Tcl commands option add *Button.relief sunken If not in option database, use default provided by class implementation

Geometry Management Widgets do not control their own positions and sizes, geometry managers do Widgets do not appear on screen until managed by geometry manager Geometry manager = algorithm for arranging slave windows relative to master window Geometry Manager Geometry of master Requested size from slave Parameters from application designer Size and location of slave Requested size for master

The Placer Simple, but not very powerful Each slave placed individually relative to its master place.x -x 0 -y 0 place.x -relx 0.5 -rely 0.5 \ -height 3c -anchor center place.x -relx 0.5 \ -y 1.0c -anchor n place.x -relheight 0.5 \ -relwidth 0.5 -relx 0 -rely 0.5

The Packer Much more powerful than placer Arranges groups of slaves together Packs slaves around edges of master’s cavity For each slave in order: 1. Pick a side of the master 2. Slice off a frame for slave 3. Possibly grow slave to fill frame 4. Position slave in frame

Packer Examples pack.a -side left pack.b -side left pack.c -side left pack.a -side top -anchor w pack.b -side top -anchor w \ -pady.5c pack.c -side top -anchor w pack.a -side top -fill x pack.b -side right -fill y pack.c -padx 0.5c -pady 1c \ -fill both.a.b.c.a.b.c.a.b.c.a.b.c.b.c.a.b.c

Packer Advantages Considers relationships between slaves –constraint-like placement –row and column arrangements easy to achieve –adjusts arrangement if slave requests a different size Requests size on behalf of master –just large enough for all slaves –adjusts if slaves request different sizes –permits hierarchical geometry management »constrains propagate in hierarchy

Widget Commands Tcl command for each widget, named after widget’s path name –created with widget Used to reconfigure, manipulate widget button.a.b.a.b configure -relief sunken.a.b flash scrollbar.x.x set x get Widget command deleted automatically when widget is destroyed Principle: all state should be readable, modifiable, anytime

Connections button release click on arrow Question: How to make widgets work together with application, other widgets? Answer: Tcl commands Widget actions are Tcl commands button.a.b -command exit Widgets use Tcl commands to communicate with each other scrollbar.x -command “.y yview” Application uses widget commands to communicate with widgets exit.y yview 9

Bindings Associate Tcl with mouse/keyboard events bind.t {backspace.t} Can select one or more windows –single window:.t –all windows in a class: Text –all windows: all Specifying events Window/TagEvent SequenceScript Modifiers Event Type Button or Keysym

Bindings (cont.) % substitutions in binding scripts –coordinates from event: %x and %y –window: %W –character from event: %A –etc. Examples bind.c {move %x %y} bind.t {insert %A} bind all {help %W} Only one binding triggers from each event for each tag/window in order –window before class before toplevel before all –if >1 binding with same tag match, most specific executes

Bindings (cont.) Binding tags –event not bound to window, class, or all is bound to a tag »any user-defined string –every window has list of binding tags –apply event to each tag in order –most specific binding that matches tag/event is executed Default –window name, class name, nearest toplevel ancestor name, all bindtags window ?tagList? –can read/modify tag list for window –add new bindings, modify order –bindtags.b {all. Button.b} - reverse default order Use to manage complex binding sets

Other Tk Commands The selection selection get selection get FILE_NAME Issuing commands to other Tk applications send tgdb “break tkEval.c:200” winfo interps returns: wish tgdb ppres Window information winfo width.x winfo children.x winfo containing $x $y

Access to Other Window Facilities Keyboard focus focus.x.y Communication with window manager wm title. “Editing main.c” wm geometry. 300x300 wm iconify. Deleting windows destroy.x Grabs grab.x grab release.x

Example 1: Dialog Box toplevel.d message.d.top -width 3i -bd 2 \ -relief raised -justify center -font \ *-helvetica-medium-r-normal--*-240-* \ -text “File main.c hasn’t been \ saved to disk since it was last \ modified. What should I do?” pack.d.top -side top -fill both

Dialog Box Cont. frame.d.bot pack.d.bot -side bottom -fill both button.d.bot.left -text “Save File” \ -command “quit save” pack.d.bot.left -side left \ -expand yes -padx 20 -pady 20 button.d.bot.mid -text “Quit Anyway” \ -command “quit quit” pack.d.bot.mid -side left \ -expand yes -padx 20 -pady 20

Dialog Box Cont. button.d.bot.right -text “Return to Editor” \ -command “quit return” pack.d.bot.right -side left \ -expand yes -padx 20 -pady 20 proc quit button { puts stdout “You pressed the \ $button button; bye-bye” destroy.d }

Example 2: Browser listbox.list -yscroll “.scroll set” \ -relief raised -width 20 -height 15 pack.list -side left scrollbar.scroll -command “.list yview” pack.scroll -side right -fill y

Browser Cont. if {$argc > 0} { set dir [lindex $argv 0] } else {set dir.} foreach i [exec ls -a $dir] {.list insert end $i }

Browser Cont. bind.list { browse $dir [selection get] bind.list {destroy.} focus.list proc browse {dir file} { if {$dir != “.”} { set file $dir/$file } if [file isdirectory $file] { exec browse $file & } else { if [file isfile $file] { exec $env(EDITOR) $file & } else { puts stdout “\”$file\” isn’t \ a regular file or directory” }

Example 3: Scrolling Canvas Top-level canvas with x and y scrollbars –20x10 array of rectangles with (i,j) index label –select and print rectangle labels –pan canvas

Example 3: Scrolling Canvas Create top level widget Inform window manager of size, title, etc. proc mkScroll {{w.cscroll}} { catch {destroy $w} toplevel $w wm geometry $w wm title $w "Scrollable Canvas Demonstration" wm iconname $w "Canvas" wm minsize $w

Scrolling Canvas Cont. Create header message and quit button message $w.msg \ -font -Adobe-Times-Medium-R-Normal-*-180-* \ -aspect 300 -relief raised -bd 2 -text {This window displays a canvas widget that can be scrolled either using the scrollbars or by dragging with button 2 in the canvas. If you click button 1 on one of the rectangles, its indices will be printed on stdout.} frame $w.frame -relief raised -bd 2 button $w.ok -text "OK" -command "destroy $w" pack $w.msg -side top -fill x pack $w.ok -side bottom -pady 5 pack $w.frame -side top -expand yes -fill both

Scrolling Canvas Cont. Create canvas and scrollbars fix maximum scrolling/drawing region set up link between scroll bars and canvas set c $w.frame.c canvas $c -scrollregion {-10c -10c 50c 20c} \ -xscroll "$w.frame.hscroll set" \ -yscroll "$w.frame.vscroll set" scrollbar $w.frame.vscroll -relief sunken \ -command "$c yview" scrollbar $w.frame.hscroll -orient horiz \ -relief sunken -command "$c xview" pack $w.frame.vscroll -side right -fill y pack $w.frame.hscroll -side bottom -fill x pack $c -expand yes -fill both

Scrolling Canvas Cont. Draw 20x10 array of rectangles and labels rectangles of background color outlined in black black text “i, j” centered in rectangle set bg [$c cget -bg] for {set i 0} {$i < 20} {incr i} { set x [expr { *$i}] for {set j 0; set y -10} {$j < 10} {incr j; incr y 3} { $c create rect ${x}c ${y}c [expr $x+2]c \ [expr $y+2]c -outline black -fill $bg -tags rect $c create text [expr $x+1]c [expr $y+1]c \ -text "$i,$j" -anchor center -tags text }

Scrolling Canvas Cont. Bind canvas item events to mouse callback procedures highlight rectangle when mouse enters it unhighlight rectangle when mouse leaves print text label when button 1 clicked over rectangle Pan canvas when dragging with button 2 down $c bind all "scrollEnter $c" $c bind all "scrollLeave $c" $c bind all "scrollButton $c" bind $c "$c scan mark %x %y" bind $c "$c scan dragto %x %y" } # end of mkScroll

Scrolling Canvas Cont. Mouse event callback procedures scrollEnter - called when entering rectangle scrollLeave - called when leaving rectangle scrollButton - called when button click in rectangle proc scrollEnter canvas { global oldFill set id [$canvas find withtag current] if {[lsearch [$canvas gettags current] text] >= 0} { set id [expr $id-1] } set oldFill [$canvas itemcget $id -fill] if {[tk colormodel $canvas] == "color"} { $canvas itemconfigure $id -fill SeaGreen1 } else { $canvas itemconfigure $id -fill black $canvas itemconfigure [expr $id+1] -fill white }

Scrolling Canvas Cont. proc scrollLeave canvas { global oldFill set id [$canvas find withtag current] if {[lsearch [$canvas gettags current] text] >= 0} { set id [expr $id-1] } $canvas itemconfigure $id -fill $oldFill $canvas itemconfigure [expr $id+1] -fill black } proc scrollButton canvas { global oldFill set id [$canvas find withtag current] if {[lsearch [$canvas gettags current] text] < 0} { set id [expr $id+1] } puts stdout "You buttoned at \ [lindex [$canvas itemconf $id -text] 4]" } mkScroll

Summary Creating interfaces with Tcl scripts is easy –create widgets –arrange with geometry managers –connect to application, each other 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