[ltk-user] ltk-tile make-instance 'button :command
herth at peter-herth.de
Tue Apr 13 20:43:47 UTC 2010
I have to say, from the general style your code basically looks like
the code I would write.
Just a few comments, none of them ltk related:
- you set some variables, but never define them, rather use let*
- what lisp are you using, SBCL has pi defined as a constant?
- and the biggest one: DON'T use read on user input carelessly, try
for example entering #.(do-msg "huch!") instead of a number and press
calculate... read allows for evaluation of arbitrary lisp code.
Of course, the dialog layout could be different, but thats just fiddling a bit
with the options of pack...
So the code could look like:
(defun circularea ()
(with-ltk (:debug-tcl nil)
(wm-title *tk* "circularea")
(let* ((label-d (make-instance 'label
:text "A circle with a diameter of "))
(entry-d (make-instance 'entry
(label-u (make-instance 'label
(label-a (make-instance 'label
:text "has an area of "))
(label-r (make-instance 'label
(label-su (make-instance 'label
:text "square units"))
(b (make-instance 'button
(let* ((diameter (let ((*read-eval* nil))
(radius (/ diameter 2))
(area (* pi (* radius radius))))
(setf (text label-r) area))))))
(pack b) )))
More information about the ltk-user