{ (define LIBNAME "GUI") (include "head.tinc") }

The teachpack gui.ss provides the following operations:

  • {(idx show-window)} : window -> true
    to show the window
  • {(idx hide-window)} : window -> true
    to hide the window
  • {(idx create-window)} : (listof (listof gui-item)) -> window
    to add gui-items to a window and to show the window
    each list of gui-items defines one row of gui items in the window
  • {(idx make-button)} : str (event% -> boolean) -> gui-item
    to create a button with label and call-back function
  • {(idx make-message)} : str -> gui-item
    to create an item that displays a message
  • {(idx draw-message)} : gui-item[message%] stri -> true
    to display a message in a message item
    it erases the current message
  • {(idx make-text)} : str -> gui-item
    to create an item (with label) that allows users to enter text
  • {(idx text-contents)} : gui-item[text%] -> str
    to determine the contents of a text field
  • {(idx make-choice)} : (listof str) -> gui-item
    to create a choice menu that permits users to choose from some string alternatives
  • {(idx choice-index)} : gui-item[choice%] -> num
    to determine which choice is currently selected in a choice-item
    the result is the 0-based index in the choice menu
  • Example 1:

    > (define w (create-window (list (list (make-button "QUIT" (lambda (e) (hide-window w)))))))
    
    A button appears on the screen. Click on the button and it will disappear.
    > (show-window w)
    
    The frame reappears.

    Example 2:

    ; text1 : GUI-ITEM
    (define text1
      (make-text "Please enter your name"))
    
    ; msg1 : GUI-ITEM
    (define msg1
      (make-message (string-append "Hello, World" (make-string 33 #\SPACE))))
    
    ; Event -> true
    ; draws the current contents of text1 into msg1, prepended with "Hello, "
    (define (respond e)
      (draw-message msg1 (string-append "Hello, " (text-contents text1))))
    
    ; set up window with three "lines": a text field, a message, and two buttons
    ; fill in text and click OKAY
    (define w 
     (create-window
      (list
       (list text1)
       (list msg1)
       (list (make-button "OKAY" respond)
    	 (make-button "QUIT" (lambda (e) (hide-window w)))))))
    
    {(include "foot.tinc")}