[ltk-user] ltk-tile make-instance 'button :command

Everett Fuller slac.in.the.box at gmail.com
Mon Apr 12 11:55:13 UTC 2010


Wow:  thanks for the wonderfully rapid response.  Yes, the latest ltk made
the issue I was having obsolete, now that tile is merged!

The weekend came, so I had a small window of time to try and put all the
pieces of this ltk stuff together and make a small window that did
something. In this case the widget computes the area of a circle, when given
the diameter--rather elementary, but a start.  Everytime I had a question, I
ended up finding answers in the archives of this mailing list!  Since it was
my first try at making a gui that did something other than say "hello," and
since I am new to lisp and new to programming in general, I am pasting this
trivial excercise in hopes that you (or any advanced ltk-user) could offer
criticism as to best practices, etc:

*;;;;; area.lisp endeavors to create a widget that calculates the area of a
circle when given a diamter*

*;; load dependent systems
(load "/usr/local/lisp/systems/ltk/ltk")
(in-package :ltk)

;; define function
(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
                   :text "0"))
       (label-u (make-instance 'label
                   :text "units"))
       (label-a (make-instance 'label
                   :text "has an area of "))
       (label-r (make-instance 'label
                   :text "0"))
       (label-su (make-instance 'label
                    :text "square units"))
       (b (make-instance 'button
                 :text "calculate"
                 :command
                 (lambda ()
                   (progn
                 (setf diameter (read-from-string (text entry-d)))
                 (setf radius (/ diameter 2))
                 (setf pi 3.145927)
                 (setf area (* pi (* radius radius)))
                 (setf (text label-r) area)
                 ))))
       )
      (pack label-d)
      (pack entry-d)
      (pack label-u)
      (pack label-a)
      (pack label-r)
      (pack label-su)
      (pack b)
      )))

;; use function
(circularea)
*

Thanks again for making gui programming possible for the rest of us.

--Everett

On Thu, Apr 8, 2010 at 2:31 PM, Peter Herth <herth at peter-herth.de> wrote:

> Hi Everett,
>
> as it is late over here, only a very brief answer: in the meantime,
> ltk-tile has been merged into
> the main ltk library, if you grab the latest ltk version from:
> http://ltk.rplay.net/svn/branches/ltk/repl/ltk.lisp
> you get a ltk which uses the tile widget set by default (assuming you
> are running tcltk 8.5 or above).
> The ltktest program contained within ltk.lisp also contains some demo
> code to switch between
> the different tile styles on your system - just try running (ltk:ltktest).
> If you have any more questions, I will gladly answer them tomorrow :)
>
> Peter
>
> _______________________________________________
> ltk-user site list
> ltk-user at common-lisp.net
> http://common-lisp.net/mailman/listinfo/ltk-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ltk-user/attachments/20100412/0055dff9/attachment.html>


More information about the ltk-user mailing list