球拍更改按钮坐标

时间:2016-04-09 09:20:18

标签: button racket

我在一个框架中有一个按钮,当我在代码中更改vert-marginhoriz-margin时,该按钮不会改变它的位置,而是框架会变小或变大。

这是代码:

(require racket/gui/base)

(define frame (new frame% [label "GUI BUILDER"]
                      [width 300]
                      [height 400]
                      [style '(no-resize-border)]))

(send frame show #t)

(define msg (new message% [parent frame]
                          [label "Text"]))

(new button% [parent frame]
             [label "Generate button code"]
             [vert-margin 200]   
             [horiz-margin 480]
             [callback (lambda (button event)
                         (send msg set-label "Changed"))])

请提供代码示例,我写了这个并且它不起作用:

(require racket/gui/base)

(define frame (new frame% [label "GUI BUILDER"]
                          [width 700]
                          [height 700]))

(send frame show #t)

(define coloana (new vertical-panel% [parent frame]))

(define cub1 (new horizontal-panel% [parent coloana]
                                    [min-height 150]))

(define cub2 (new horizontal-panel% [parent coloana]
                                    [min-height 50]))

(define cub3 (new horizontal-panel% [parent cub2]
                                    [min-width 50]))

(define buton (new button% [parent cub1]
                           [label "Generate button code"]))

1 个答案:

答案 0 :(得分:0)

frame%默认为可拉伸的宽度和高度。 而不是使用边距将按钮放在特定位置, 我建议将空面板放在按钮的顶部和左侧。

#lang racket
(require racket/gui/base)

(define frame
  (new frame% [label "GUI BUILDER"]
       [width 300]
       [height 400]
       [style '(no-resize-border)]))

(define row1
  (new horizontal-panel%
       [parent frame]
       [min-width   300]
       [min-height   50]
       [style       '(border)]
       [stretchable-height #f]))

(define row2
  (new horizontal-panel%
       [parent frame]
       [stretchable-height #f]))

(define row3
  (new horizontal-panel%
       [parent frame]
       [style '(border)]
       [stretchable-height #t]))

(define col-2-1              ; row 2 column1
  (new vertical-panel%
       [parent row2]
       [min-width 100]
       [style '(border)]
       [stretchable-height #t]))

(new message% [parent row1]    [label "row1"])
(new message% [parent col-2-1] [label "col-2-1"])
(new message% [parent row3]    [label "row3"])

(define button-msg (new message% [parent row1] [label "Text                   "]))

(define button (new button%
                    [parent       row2]
                    [label        "Click"]
                    [vert-margin  0]   
                    [horiz-margin 0]
                    [style        '(border)]
                    [callback     (λ (button event)
                                    (send button-msg set-label "Changed"))]))

(send frame show #t)

The Frame