Google

link="#009900" vlink="#007700" alink="#cc0000"> Teachpacks for How to Design Programs

GUI


gui.ss

The teachpack gui.ss provides the following operations:

  • show-window : -> true
    to show the window
  • hide-window : -> true
    to hide the window
  • create-window : (listof (listof gui-item)) -> true
    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
  • make-button : str (event% -> boolean) -> gui-item
    to create a button with label and call-back function
  • make-message : str -> gui-item
    to create an item that displays a message
  • draw-message : gui-item[message%] stri -> true
    to display a message in a message item
    it earses the current message
  • make-text : str -> gui-item
    to create an item (with label) that allows users to enter text
  • text-contents : gui-item[text%] -> str
    to determine the contents of a text field
  • make-choice : (listof str) -> gui-item
    to create a choice menu that permits users to choose from some string alternatives
  • 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:

    > (create-window (list (list (make-button "QUIT" hide-window))))
    
    A button appears on the screen. Click on the button and it will disappear.
    > (show-window)
    
    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
    (create-window 
     (list
      (list text1)
      (list msg1)
      (list (make-button "OKAY" respond)
            (make-button "QUIT" hide-window))))