Reputation: 103
My first LTK-application. Trying to execute function with argument from entry-field.
(defpackage :test
(:use :cl
:ltk))
(in-package :test)
(defun main()
(with-ltk ()
(let* ((f (make-instance 'frame
:height 200
:width 300))
(e (make-instance 'entry
:master f
))
(b (make-instance 'button
:master f
:text "Go"
:command (test (text e)))))
(wm-title *tk* "Test")
(pack f)
(pack e :side :left)
(pack b :side :left)
(configure f :borderwidth 3)
(configure f :relief :sunken))))
(defun test (str)
(format t "String: ~a" str))
Why function execute just once, when source is launched? And then - any actions.
Upvotes: 3
Views: 662
Reputation: 9451
If you want to pass a callback, use (lambda () ...)
, i.e. in your code:
...
(b (make-instance 'button
:master f
:text "Go"
:command (lambda () (test (text e))))))
Otherwise, your (test (text e))
is executed at the time of make-instance
call, before the object is initialized.
It's easier to spot this problems, if you turn on debug output: (setf ltk:*debug-tk* t)
Upvotes: 3