【问题标题】:Strange behavior of racket GUI `timer%`球拍 GUI `timer%` 的奇怪行为
【发布时间】:2018-09-03 19:18:09
【问题描述】:

我正在尝试编写一个简单的程序,它显示当前时间并每秒更新一次。但是,当我运行下面的代码时

#lang racket/gui

(require racket/date)

(define frame (new frame%
                   [label "Not Functioning Timer"]
                   [width 300]
                   [height 100]))

(new timer%
     [interval 1000]
     [notify-callback (lambda ()
                        ;(display (format "The time is: ~a"
                        ;                 (date->string (current-date) #t)))
                        ;(newline) ; the commented lines work
                        ;; however the behavior of the following lines is weird
                        (send time-msg
                              set-label
                              (format "The time is: ~a"
                                      (date->string (current-date) #t))))])


(define time-msg (new message%
                      [parent frame]
                      [label "nothing so far..."]))

(send frame show #t)

我明白了

缺少涉及当前时间的描述。但是,当我取消注释 (display ...) 行时,它会产生输出:

(object:timer% ...)
The time is: Monday, March 26th, 2018 12:14:33am
The time is: Monday, March 26th, 2018 12:14:34am
The time is: Monday, March 26th, 2018 12:14:35am
The time is: Monday, March 26th, 2018 12:14:36am
...

哪个功能好。

我不明白为什么会这样。请帮忙!

顺便问一下,我应该怎么做才能将文本对齐到左侧而不是放在中心?

谢谢。

【问题讨论】:

    标签: user-interface racket


    【解决方案1】:

    问题是组件在首次渲染容器时调整大小。那你的留言时间太长了。

    (define time-msg (new message%
                          [parent frame]
                          [auto-resize #t]
                          [label "nothing so far..."]))
    

    如果您将auto-resize 属性设置为#t,您应该会看到您想要的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-01
      • 2019-01-28
      • 1970-01-01
      • 2013-07-14
      • 1970-01-01
      相关资源
      最近更新 更多