[ltk-user] Another newbie question..

Neil Baylis neil.baylis at gmail.com
Tue Mar 11 04:46:27 UTC 2008


Hi,

I managed to get myself sorted out with my previous question.

Now I'm having trouble adding a button to my application. I'm not sure
whether this is a lisp question, or an ltk question, so please bear
with me. Here's a simplified version of the failing code:


(in-package :ltk)
(defparameter *cvs* nil)

(defun draw-circle (x y radius color)
  (format t "B Canvas is ~a~%" *cvs*)
  (itemconfigure
   *cvs*
   (create-oval *cvs*
 (- x radius) (- y radius)
 (+ x radius) (+ y radius))
   :outline color))

(defun testit ()
  (with-ltk ()
    (let* ((*cvs* (make-instance 'canvas :width 200 :height 200))
   (b (make-instance 'button
     :master nil
     :text "Do it!"
     :command (lambda ()
 (draw-circle 100 100 20 :red)))))

      (format t "A Canvas is ~a~%" *cvs*)
      (pack *cvs*)
      (pack b)
      (draw-circle 100 100 40 :blue))))

When I load this, and call the function testit from the REPL, it
displays the blue circle correctly, but fails to display the red one.
Here is what I see in the REPL:


CL-USER> (load "testit.lisp")
#P"/Users/neil/devel/lispgui/testit.lisp"
CL-USER> (in-package :ltk)
#<Package "LTK">
LTK> (testit)
A Canvas is #<CANVAS #x873D586>
B Canvas is #<CANVAS #x873D586>
B Canvas is NIL

It prints the "B Canvas is NIL" when I click on the button, so this is
obviously why it fails to draw the red circle. But, I don't understand
why *cvs* is nil in this case. I'm sure this is painfully obvious, but
not to me. Can someone point me in the right direction please?

Neil.



More information about the ltk-user mailing list