Display
A Display is the window your GUI objects appear in. Build a GUI by adding shapes, images, text, and controls to it with add(). The window opens as soon as you create it. Inside the display the origin (0, 0) is the top-left corner; x increases to the right and y increases downward.
A program may have several displays open. Displays may contain any number of GUI objects, but they cannot contain another display.
Once a display has been created, you populate it by placing various GUI widgets and graphics objects on it. The library provides various GUI widgets and graphics objects.
Creating a Display
You can create a Display using the following functions:
Display()
Display(title, width, height, x, y, color)
| Parameter | Type | Default | Description |
|---|---|---|---|
title |
str |
'' |
The window title. |
width |
int or float |
600 |
The window width, in pixels. |
height |
int or float |
400 |
The window height, in pixels. |
x |
int or float |
0 |
The horizontal position of the window's top-left corner on the screen, in pixels. |
y |
int or float |
50 |
The vertical position of the window's top-left corner on the screen, in pixels. |
color |
Color |
Color.WHITE |
The background color. |
For example,
display = Display("Simple GUI", 120, 60)
Functions
Once a Display display has been created, the following functions are available:
| Function | Description |
|---|---|
display.add(item) |
Add a GUI object to the display at the given position. |
display.remove(item) |
Remove a GUI object from the display. |
display.removeAll() |
Remove every GUI object from the display. |
display.move(item, x, y) |
Move a GUI object to a new position on the display. |
display.getItems() |
Return the GUI objects currently on the display. |
Layering GUI Objects
GUI objects on a Display are layered. Typically, the most recent object sits on top of the others (order = 0). You can change the order
| Function | Description |
|---|---|
display.addOrder(item) |
Add a GUI object to the display at the given position and layer. |
display.getOrder(item) |
Return the layer a GUI object sits on. |
display.setOrder(item, order) |
Move a GUI object to a different layer. |
Adding Menus
Menu objects are different from other objects; instead of appearing on a Display, menu objects are added to the Display's menu bar, or as context (right click, pop-up) menus.
| Function | Description |
|---|---|
display.addMenu(menu) |
Add a menu to the display's menu bar. |
display.addPopupMenu(menu) |
Add a pop-up (right-click) menu to the display. |
Manipulating the Display
These functions are useful for updating how a Display appears on the screen.
| Function | Description |
|---|---|
display.getTitle() |
Return the display's title. |
display.getSize() |
Return the display's width and height. |
display.getWidth() |
Return the display's width. |
display.getHeight() |
Return the display's height. |
display.getPosition() |
Return the display's position on the screen. |
display.getColor() |
Return the display's background color. |
display.setTitle(title) |
Set the display's title. |
display.setSize(width, height) |
Set the display's width and height. |
display.setWidth(width) |
Set the display's width. |
display.setHeight(height) |
Set the display's height. |
display.setPosition(x, y) |
Set the display's position on the screen. |
display.setColor() |
Set the display's background color. |
display.show() |
Show the display. |
display.hide() |
Hide the display. |
display.close() |
Close the display. |
display.save(filename) |
Save a picture of the display to an image file. |
display.setToolTipText() |
Set the hover text shown over the display. |
display.showMouseCoordinates() |
Show the mouse position in the display's tooltip as the mouse moves. |
display.hideMouseCoordinates() |
Stop showing the mouse position in the display's tooltip. |
Drawing Shapes
In addition to adding movable GUI objects to a Display, you can also draw shapes and text directly to the Display's background. Drawing shapes is faster than adding GUI objects, but drawn shapes can't be moved or erased without clearing the entire canvas (using clearDrawing()).
| Function | Description |
|---|---|
display.drawRectangle(x1, y1, x2, y2) |
Draw a rectangle straight onto the display. |
display.drawOval(x1, y1, x2, y2) |
Draw an oval straight onto the display. |
display.drawCircle(x, y, radius) |
Draw a circle straight onto the display. |
display.drawPoint(x, y) |
Draw a single point straight onto the display. |
display.drawArc(x1, y1, x2, y2) |
Draw an arc straight onto the display. |
display.drawArcCircle(x, y, radius) |
Draw a circular arc straight onto the display. |
display.drawPolyline(xPoints, yPoints) |
Draw a connected series of line segments straight onto the display. |
display.drawLine(x1, y1, x2, y2) |
Draw a line straight onto the display. |
display.drawPolygon(xPoints, yPoints) |
Draw a polygon straight onto the display. |
display.drawIcon(filename, x, y) |
Draw an image straight onto the display. |
display.drawLabel(text, x, y) |
Draw a line of text straight onto the display. |
display.drawText(text, x, y) |
Draw a line of text straight onto the display. |
display.clearDrawing() |
Erase everything drawn with the draw… methods. |
Events
Displays have the same event functions as other GUI objects, plus their own onClose() event.
| Function | Description |
|---|---|
display.onClose(action) |
Set up a function to call right before the display closes. |
display.onMouseClick(action) |
Set up a function to call when the mouse is clicked on this object. |
display.onMouseDown(action) |
Set up a function to call when the mouse button is pressed on this object. |
display.onMouseUp(action) |
Set up a function to call when the mouse button is released over this object. |
display.onMouseMove(action) |
Set up a function to call when the mouse moves over this object. |
display.onMouseDrag(action) |
Set up a function to call when the mouse is dragged over this object. |
display.onMouseEnter(action) |
Set up a function to call when the mouse moves onto this object. |
display.onMouseExit(action) |
Set up a function to call when the mouse moves off this object. |
display.onKeyType(action) |
Set up a function to call when a key is typed (pressed and released). |
display.onKeyDown(action) |
Set up a function to call when a key is pressed down. |
display.onKeyUp(action) |
Set up a function to call when a key is released. |