Teachpacks

1`` | Ht DP Teachpacks
2`` | Ht DC Teachpacks

On this page:

create-window
window?
show-window
hide-window
make-button
make-message
draw-message
make-text
text-contents
make-choice
choice-index

Version: 4.0.2
contents
← prev up next →

#### 1.12`` Simple Graphical User Interfaces: gui.ss

The teachpack provides operations for creating and manipulating graphical user interfaces. We recommend using the world teachpack instead.

Window A Window is a data representation of a visible window on your computer screen.

GUI-ITEM A GUI-Item is a data representation of an active component of a window on your computer screen.

(create-window g) → Window
g : (listof (listof GUI-ITEM))

Creates a window from the “matrix” of gui items g.

(window? x) → boolean?
x : any/c

Is the given value a window?

(show-window w) → true
w : Window

Shows w.

(hide-window w) → true
w : window

Hides w.

(make-button label callback) → GUI-ITEM
label : string>
callback : (-> event% boolean)

Creates a button with label and callback function. The latter receives an argument that it may safely ignore.

(make-message msg) → GUI-ITEM
msg : string?

Creates a message item from msg.

(draw-message g m) → true
g : GUI-ITEM
m : string?

Displays m in message item g and erases the current message.

(make-text txt) → GUI-ITEM
txt : string?

Creates an text editor (with label txt) that allows users to enter text.

(text-contents g) → string?
g : GUI-ITEM

Determines the current contents of a text GUI-ITEM.

(make-choice choices) → GUI-ITEM
choices : (listof string?)

Creates a choice menu from choices that permits users to choose from some alternatives.

(choice-index g) → natural-number/c
g : GUI-ITEM

Determines the choice that is currently selected in a choice GUI-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 b u t t o n a p p e a r s o n t h e s c r e e n.
; C l i c k o n t h e b u t t o n a n d i t w i l l d i s a p p e a r.
> (show-window w)
; T h e w i n d o w d i s a p p e a r s.

Example 2:

; t e x t 1 : G U I-I T E M
(define text1
(make-text "Please enter your name"))
; m s g 1 : G U I-I T E M
(define msg1
(make-message (string-append "Hello, World" (make-string 33 #\space))))
; E v e n t -> t r u e
; d r a w s t h e c u r r e n t c o n t e n t s o f t e x t 1 i n t o m s g 1, p r e p e n d e d w i t h "H e l l o, "
(define (respond e)
(draw-message msg1 (string-append "Hello, " (text-contents text1))))
; s e t u p w i n d o w w i t h t h r e e "l i n e s":
; a t e x t f i e l d, a m e s s a g e, a n d t w o b u t t o n s
; f i l l i n t e x t a n d c l i c k O K A Y
(define w
(create-window
(list
(list text1)
(list msg1)
(list (make-button "OKAY" respond)
(make-button "QUIT" (lambda (e) (hide-window w)))))))

contents
← prev up next →