【发布时间】: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