Documentation
Not logged in

Copyright (C) 2009-2010, Trevor Davel <twylite AT crypt DOT co DOT za>
See the file "LICENSE.txt" (Tcl/Tk License) for information on usage and redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.


tk::wprop 1.x

Overview

A mechanism to associate properties (variables) with a Tk window.

[wprop] is handy for creating simple reusable multi-instance helper GUIs that may not warrant a megawidget solution. It can be used to add multi-instance capability to single-instance GUIs implemented in a namespace (bound to namespace vars).

Multi-instance capacity is important for reusable dialogs that have some state information that should persist in a specific context while the application is running (e.g. last used directory for a specific file dialog, current tab for a configuration dialog, values in a Find/Replace dialog).

Quick reference

wprop set $win propname value -> value
wprop get $win propname -> value
wprop get $win -> (dict of property names and values)
wprop exists $win propname -> bool
wprop get? $win propname -> (value or {})
wprop unset $win propname -> {}
wprop unset $win -> {}
wprop variable $win propname -> (fully qualified variable name for property)

Example of use

  package require tk::wprop 1.0
  
  proc person_entry_dialog {win} {
  
    toplevel $win
    wprop set $win modalresult {}
    
    foreach field {Name Address Age Telephone} {
      set key [string tolower $field]
      wprop set $win $key {}
      grid [label $win._${key} -text $field] \
        [entry $win.$key -textvariable [wprop variable $win $key]] 
    }
    
    grid x [button $win.ok -text "OK" -command [list apply {{win} {
      wm withdraw $win
      wprop set $win modalresult ok
    }} $win]]
    
    return $win        
  }
  
  person_entry_dialog .pdlg
  vwait [wprop variable .pdlg modalresult]
  set person_info [wprop get .pdlg]
  destroy .pdlg

Known issues

Ideas