1.12 Simple Graphical User Interfaces: "gui.ss"

► |  | Teachpacks

1 | Ht DP Teachpacks
2 | Ht DP/ 2e Teachpacks

▼ | 1 | Ht DP Teachpacks

1.1 | Manipulating Images: "image.ss"
1.2 | Simulations and Animations: "world.ss"
1.3 | Converting Temperatures: "convert.ss"
1.4 | Guessing Numbers: "guess.ss"
1.5 | Master Minding: "master.ss"
1.6 | Simple Drawing: "draw.ss"
1.7 | Hangman: "hangman.ss"
1.8 | Managing Control Arrows: "arrow.ss"
1.9 | Manipulating Simple HTML Documents: "docs.ss"
1.10 | Working with Files and Directories: "dir.ss"
1.11 | Graphing Functions: "graphing.ss"
1.12 | Simple Graphical User Interfaces: "gui.ss"
1.13 | An Arrow GUI: "arrow-gui.ss"
1.14 | Controlling an Elevator: "elevator.ss"
1.15 | Queens: "show-queen.ss"
1.16 | Matrix Operations: "matrix.ss"

On this page:

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

top← 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 button appears on the screen.
; Click on the button and it will disappear.
> ( show-window w)
; The window disappears.

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)))))))

top← prev up next →