【问题标题】:How to to have expanding canvas fill more then half the screen如何让扩展画布填充超过一半的屏幕
【发布时间】:2019-07-23 10:08:56
【问题描述】:

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

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

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

展开后是这样的:

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

我在 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)

【问题讨论】:

  • 你试过grid geometry manager吗?
  • 不,我没有,但可能值得一看。也许比pack@Ehvince 更容易理解。

标签: common-lisp tk


【解决方案1】:

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

Tcl/Tk: Frames misbehave when resizing.

它进行了轻微的翻译,但删除右侧面板的: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))))

这解决了提出的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 2022-11-10
    • 2019-04-01
    相关资源
    最近更新 更多