Skip to content
Andrej Vodopivec edited this page Mar 13, 2015 · 4 revisions

Children windows are positioned into parent with geometry managers. There are three geometry managers, grid, pack and place. pack is a very simple geometry manager, for most situations you want to use the grig manager. You can only use one manager for each parent window.

Grid manager

Windows are placed in a n x m grid. The position in the grid is selected with the :column and :row options. Windows can span across multiple rows/columns using the :rowspan/:columnspan options. Inside the cell, the window is positioned with the :sticky option (can be any combination of "n","s","w","e").

Functions for the grid manager:

  • (grid wlist &rest options)
  • (grid-configure w &rest options)
  • (grid-columnconfigure w i &rest options)
  • (grid-info w)
  • (grid-rowconfigure w i &rest options)
  • (grid-forget w)
  • (grid-slaves w &key row column)

Tcl/Tk documentation for grid.

Pack manager

Windows are placed into the master with the :side option (can be "left", "right", "top" (default) or "bottom"). The placement can be configure with the :anchor ("n", "w", "e", "s" or "center"), :expand (t or nil) and :fill ("x", "y" or "both") options.

Functions for the pack manager:

  • (pack wlist &rest options)
  • (pack-configure w &rest options)
  • (pack-forget w)
  • (pack-info w)
  • (pack-slaves w)

Tcl/Tk documentation for pack.

Place manager

Children are placed into the parent according to :x and :y options.

Functions for the place manager:

  • (place wlist &rest options)
  • (place-configure w &rest options)
  • (place-forget w)
  • (place-info w)
  • (place-slaves w)

Tcl/Tk documentation for place

Example for the grid manager

Grid manager

(defpackage :tk-user
  (:use :cl :tk)
  (:export :main))

(in-package :tk-user)

(defun main ()
  (with-tk-root (root)
    (setf (window-title root) "Grid")

    (let ((onevar (boolean-var))
          (twovar (boolean-var))
          (threevar (boolean-var))
          (f (frame :parent root :padding '(5 5 5 5))))
      
      (setf (var-value onevar) t
            (var-value twovar) nil
            (var-value threevar) t)
      
      (pack f :expand t :fill "both")
      
      (grid (frame :parent f :relief "sunken" :width 300 :height 200)
            :column 0 :row 0 :sticky "nsew"
            :columnspan 3 :rowspan 2)
      (grid (label :parent f :text "Name")
            :column 3 :row 0 :columnspan 2 :sticky "w")
      (grid (entry :parent f)
            :column 3 :row 1 :sticky "new"
            :columnspan 2)
      (grid (checkbutton :text "One" :parent f :variable onevar)
            :column 0 :row 3)
      (grid (checkbutton :text "Two" :parent f :variable twovar)
            :column 1 :row 3)
      (grid (checkbutton :text "Three" :parent f :variable threevar)
            :column 2 :row 3)
      (grid (button :text "OK" :parent f)
            :column 3 :row 3)
      (grid (button :text "Cancel" :parent f)
            :column 4 :row 3)

      (grid-rowconfigure f 1 :weight 1)
      (grid-columnconfigure f 0 :weight 3)
      (grid-columnconfigure f 1 :weight 3)
      (grid-columnconfigure f 2 :weight 3)
      (grid-columnconfigure f 3 :weight 1)
      (grid-columnconfigure f 4 :weight 1)

      (dolist (s (grid-slaves f))
        (grid-configure s :padx 2 :pady 2)))))
Clone this wiki locally