gpt4 book ai didi

common-lisp - LTK,按钮操作

转载 作者:行者123 更新时间:2023-12-02 00:28:19 25 4
gpt4 key购买 nike

我的第一个 LTK 应用程序。尝试使用输入字段中的参数执行函数。

(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))

为什么函数只执行一次,当源启动时?然后 - 任何 Action 。

最佳答案

如果你想传递回调,使用(lambda () ...),即在你的代码中:

...
(b (make-instance 'button
:master f
:text "Go"
:command (lambda () (test (text e))))))

否则,您的(test (text e)) 会在make-instance 调用时执行,在对象初始化之前。

如果您打开调试输出,则更容易发现此问题:(setf ltk:*debug-tk* t)

关于common-lisp - LTK,按钮操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7945620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com