Hi,
I am working through the tk tutorial using ltk
http://www.tkdocs.com/tutorial/firstexample.html
One of the first examples is a feet-to-meter converter.
At some point, the padding of the widgets is set by looping through
the children of the mainframe.
foreach w [winfo children .c] {grid configure $w -padx 5 -pady 5}
Q1: How can I do this with ltk ? Is there a function that returns the list
of the children of a widget ?
Q2: The *cursor* variable lists "X_cursor" as its first element, but tk
reports an error.
(with-ltk nil
(pack (make-instance 'button
:text "some" :cursor "X_cursor" :width 15)))
=> Tcl/Tk error: bad cursor spec "x_cursor"
This is the sole cursor in *cursor* that produces an error.
I am using gnu/linux on debian squeeze stable and tk 8.5.
Finally, here is my attempt at building the converter. It seems to work, I welcome
any comments or advices.
(defun calculate (arg)
(let* ((*read-eval* nil)
(num (read-from-string arg)))
(if (numberp num) (format nil "~,4f" (* 0.3048 num)) "" )))
(defun converter-ltk ()
(with-ltk ()
(let* ((mainframe (make-instance 'frame :padding "\"3 3 12 12\""))
(feet-entry (make-instance 'entry :width 7 :master mainframe))
(label-1 (make-instance 'label :master mainframe))
(label-2 (make-instance 'label :text "feet" :master mainframe))
(label-3 (make-instance 'label :text "is equivalent to"
:master mainframe))
(label-4 (make-instance 'label :text "meters" :master mainframe))
(calc (make-instance 'button :text "Calculate" :master mainframe
:command
(lambda ()
(setf (text label-1)
(calculate (text feet-entry)))))))
(bind feet-entry "<Return>" (lambda (evt)
(declare (ignore evt))
(setf (text label-1)
(calculate (text feet-entry)))))
(wm-title *tk* "Feet to Meters")
(grid mainframe 0 0 :sticky "nesw")
(grid-columnconfigure mainframe 0 :weight 1)
(grid-rowconfigure mainframe 0 :weight 1)
(grid feet-entry 1 2 :sticky "we")
(grid label-1 2 2 :sticky "we")
(grid label-2 1 3 :sticky "w")
(grid label-3 2 1 :sticky "e")
(grid label-4 2 3 :sticky "w")
(grid calc 3 3 :sticky "w")
; (loop for child in (children mainframe "winfo") ;; ??
; do (configure child :padx 5 :pady 5)) ;; ??
(focus feet-entry))))