(require :ltk)

(in-package :cl-user)

(defpackage :ltk-add
  (:use :common-lisp :ltk)
  (:export :ltk-add))

(in-package :ltk-add)

(defun add-numbers (a b)
  (let ((str (concatenate 'string
                          "A + B = "
                          (format nil "~d" (+ (parse-integer a)
                                              (parse-integer b))))))
    (message-box str "Solution" :ok :info)))

(defun ltk-add ()
  (with-ltk ()
    (let* ((a-frame (make-instance 'frame))
           (a-label (make-instance 'label
                                   :master a-frame
                                   :text "A ="
                                   :anchor :w))
           (a-entry (make-instance 'entry
                                   :master a-frame
                                   :text "0"))
           (b-frame (make-instance 'frame))
           (b-label (make-instance 'label
                                   :master b-frame
                                   :text "B ="
                                   :anchor :w))
           (b-entry (make-instance 'entry
                                   :master b-frame
                                   :text "0"))
           (add-button (make-instance 'button
                                      :text "Add"
                                      :command #'(lambda ()
                                                   (add-numbers
                                                    (text a-entry)
                                                    (text b-entry))))))
      (wm-title *tk* "LTK Add")
      (pack (list a-label a-entry) :side :left)
      (pack (list b-label b-entry) :side :left)
      (pack (list a-frame b-frame add-button) :fill :x)
      (bind *tk* "<Escape>" #'(lambda (event)
                                (declare (ignore event))
                                (setf *exit-mainloop* t))))))