3

我开始从事一些 GUI 编程并决定使用 ltk。Ltk 代表“lisp 工具包”,它在基本的 tcl / tk 命令上提供了一个 lispy 语法层。在某种程度上,它很像 Python 的 Tkinter。

然而,我发现,当将两张画布放在一个框架中并让其中一个在两个方向上展开时。该画布不会扩展到屏幕的中点。

为了说明我的意思,我将提供一些图片。这是创建后的窗口。

一个小窗户

展开后是这样的:

有 bug 的大窗口

我现在正试图摆脱浅灰色区域,但无论我做什么,左侧画布似乎都不想进入屏幕的右半部分。

我在 linux mint 上运行它,但这并不重要。我使用的是 2019 年 2 月 2 日发布的 ltk 版本。我试过弄乱当前的关键字参数,但我什么也没做。

这是导致这些屏幕的代码。

(in-package :ltk)

(defun scribble ()
  (with-ltk ()
    (let* ((frame (make-instance 'frame))
           (canvas (make-instance 'canvas
                                  :master frame
                                  :background "white"))
           (color-panel (make-instance 'canvas
                                       :master frame
                                       :width 400
                                       :background "grey")))
      (pack frame
            :expand t
            :fill :both)
      (pack color-panel
            :side :right
            :expand t
            :fill :y
            :anchor :e)
      (pack canvas
            :side :left
            :expand t
            :fill :both
            :anchor :w))))

;; To run the code, just run this function (in REPL or otherwise)
(scribble)
4

1 回答 1

1

我有点想通了。我仍然不完全确定 tk 是如何工作的,但是从另一个答案中我得到了修复它的信息。

Tcl/Tk:调整大小时帧行为异常。

它进行了轻微的翻译,但删除了:expand右侧面板的选项设法解决了这个问题。新代码现在如下所示:

(in-package :ltk)

(defun scribble ()
  (with-ltk ()
    (let* ((frame (make-instance 'frame))
           (canvas (make-instance 'canvas
                                  :master frame
                                  :background "white"))
           (color-panel (make-instance 'canvas
                                       :master frame
                                       :width 400
                                       :background "grey")))
      (pack frame
            :expand t
            :fill :both)
      (pack color-panel
            :side :right
            ;; The :expand option has been removed!
            :fill :y
            :anchor :e)
      (pack canvas
            :side :left
            :expand t
            :fill :both
            :anchor :w))))

这解决了提出的问题。

于 2019-07-23T11:07:35.790 回答