0

How can I set the maximum window size of a LTK window?

(ql:quickload "ltk")

(defpackage :pub-quiz
  (:use :ltk :cl))

(in-package :pub-quiz)

(defun pub-quiz-window ()
  (with-ltk ()
    (let* ((f (make-instance 'frame :relief :groove :height 500 :width 300))
           (pub (make-instance 'label :master f :text "Pub Quiz"))
           (outtext (make-instance 'text :font "monospaced" :wrap :word))
           (tf (make-instance 'text  :font "monospaced")))
      (pack f)
      (pack pub :side :left)
      (pack outtext :ipady 100)
      (pack tf))))

If I set the frame size to height and width like in the above code sample, my window wm does not respect these values at all.

The Tk docs have this

wm maxsize .window 500 500

but I don't know how to translate this into something LTK understands.

4

2 回答 2

1

我没有使用过 LTK,所以我不能对应该如何完成提出太多要求;我只是根据我在网上找到的答案来回答。LTK 手册在第3.7 节中提到有一个maxsize功能:

(maxsize toplevel width height)

以像素为单位设置窗口的最大尺寸。

调用(maxsize f 500 500)虽然不起作用。的实现maxsize是:

(defgeneric maxsize (widget x y))
(defmethod maxsize ((w widget) x y)
  (format-wish "wm maxsize ~a ~a ~a" (widget-path w) (tk-number x) (tk-number y))
  w)

我认为数字翻译工作得很好(ltk::tk-number 500) => 500。但是,(widget-path f)对于f您的代码中的 ,返回.wc,而不是.window您发布的 TK 片段显示的。您可以直接运行该代码

(format-wish "wm maxsize .window 500 500")

但这也会导致错误:

Tcl/Tk error: bad window path name ".window"

我不确定在这种情况下哪个元素的路径对你有用,但似乎一旦你找到了它,maxsize就会做你需要的事情。有一个toplevel类,调用maxsize它的实例似乎有效,所以也许你应该探索

(let* ((f (make-instance 'toplevel :relief :groove :height 500 :width 300))
       ...)
  ...
  (maxsize f 500 500))

玩弄它,我可以让它发挥作用,尽管“Pub Quiz”标签似乎一直作为一个单独的窗口出现......</p>

于 2013-09-30T15:39:42.640 回答
0

我不确定我是否正确理解了您的查询,但鉴于标题我假设您要确保打开的窗口不能扩展到给定尺寸之外?

如果是这样,您必须设置.可通过以下方式访问的主窗口*tk*

(defun pub-quiz-window ()
  (maxsize *tk* 300 300)
  (minsize *tk* 300 300)
  (let* ((f (make-instance 'frame :relief :groove :height 50 :width 30))
         (pub (make-instance 'label :master f :text "Pub Quiz"))
         (outtext (make-instance 'text :font "monospaced" :width 10 :height 10))
         (tf (make-instance 'text  :font "monospaced" :height 10 :width 10)))
    (pack f :side :left)
    (pack pub :side :left)
    (pack outtext :side :left)
    (pack tf :side :left)))

(defun create-local-view ()
  (with-ltk ()
    (pub-quiz-window)))
于 2020-08-14T14:02:49.423 回答