如何让 Ltk 显示用户正在编写的内容以及函数打印的内容?

发布于 2024-07-08 19:39:58 字数 431 浏览 5 评论 0原文

功能的种类是这样的:

(defun display-all ()
  "Display all items in the database."
  (dolist (item *database*)
    (format t "~{~a:~10t~a~%~}~%" item)))

(defun prompt-read (prompt)
  (format *query-io* "~a: " prompt)
  (force-output *query-io*)
  (read-line *query-io*))

(defun prompt-for-item ()
  (make-database
   (prompt-read "Name")
   (prompt-read "Price")))

我已经阅读了 Ltk 文档,但似乎没有任何文本小部件使​​用的示例。

The kind of functions are of the sort of:

(defun display-all ()
  "Display all items in the database."
  (dolist (item *database*)
    (format t "~{~a:~10t~a~%~}~%" item)))

(defun prompt-read (prompt)
  (format *query-io* "~a: " prompt)
  (force-output *query-io*)
  (read-line *query-io*))

(defun prompt-for-item ()
  (make-database
   (prompt-read "Name")
   (prompt-read "Price")))

I've read the Ltk documentation, but there doesn't seem to be any examples of text widget usage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸢与 2024-07-15 19:39:58

您可以像创建其他小部件一样创建文本小部件。 Lisp 端对象具有带有 writer 方法的 text 访问器函数,该函数在 Tk 端设置文本。 最小的例子:

(with-ltk ()
  (let* ((text-widget (make-instance 'text :width 15 :height 2))
         (b1 (make-instance 'button
                            :text "Print"
                            :command #'(lambda () (princ (text text-widget)))))
         (b2 (make-instance 'button :text "Reset"
                            :command #'(lambda () (setf (text text-widget) "reset")))))
    (pack text-widget)
    (pack b1)
    (pack b2)))

You create the text widget like every other widget. The Lisp-side object has text accessor function with writer method which sets the text on Tk side. Minimal example:

(with-ltk ()
  (let* ((text-widget (make-instance 'text :width 15 :height 2))
         (b1 (make-instance 'button
                            :text "Print"
                            :command #'(lambda () (princ (text text-widget)))))
         (b2 (make-instance 'button :text "Reset"
                            :command #'(lambda () (setf (text text-widget) "reset")))))
    (pack text-widget)
    (pack b1)
    (pack b2)))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文