2016-04-22 37 views
1

只需要一個包裝輸入的文本字段%一個基本的例子如何使用球拍GUI插件包在文本字段中輸入文本

(define blogPost% 
    (class horizontal-panel% 
    (super-new) 
    (define (callback button event) 
     (define title-new-value (send titleoutput get-value)) 
     (define new-value (send output get-value)) 
     (save title-new-value new-value)) 
     ;;(display title-new-value) 
     ;;(display new-value)) 
    (define button (new button% (label "Submit") 
         (vert-margin 0) 
         (parent this) 
         (callback callback))) 
    (define titleoutput (new text-field% (label " title") 
          (min-height 20) 
          (min-width 200) 
          (parent this))) 
    (define output (new text-field% (label "blog") 
         (min-height 450) 
         (min-width 400) 
         (stretchable-width 300) 
         (vert-margin 0) 
         (parent this))) 
    )) 


(define f (new frame% (label "prism blog post GUI") (min-width 400) (min-height 500))) 

(define tib (new blogPost% 
       (parent f))) 

(send f show #t) 

有更多的這個,基本上它節省了用戶的輸入到我們計劃可以訪問並打印到屏幕的數據庫中。但是,用戶在輸入文本字段時只需在一行中水平輸入,並且不會進行文字換行,並且輸入按鈕不會換行。這個問題是否可以解決?

+0

嘗試運行示例時,出現未綁定的標識符錯誤。 'callback'定義中的'save'是什麼? –

回答

1

要允許多行輸入到一個文本字段,你需要添加[style '(multiple)]的初始化參數是這樣的:

(define output (new text-field% [label "blog"] 
         [style '(multiple)] 
         [min-height 450] 
         [min-width 400] 
         [stretchable-width 300] 
         [vert-margin 0] 
         [parent this])) 

然後文本字段可以換行,並環繞文字時,行得太長。

此文檔是here。在這方面,它說:

有兩個文本字段風格:

  • 單個文本行是可見的,並且當用戶按下回車鍵,否則會生成一個特殊的控制事件的輸入(當文本字段具有焦點),並且該事件不由文本字段的框架或對話框處理(請參閱top-level-window<%>中的on-traverse-char)。

  • 多行文本是可見的,並且Enter沒有專門處理。

後來,它指定樣式參數是一個符號列表,並說:

樣式必須包含的'single'multiple只有一個;前者指定單行字段,後者指定多行字段。