TextField
Create a single-line text field the user can type into.
If you create a TextField with a callback function, then that function will be called anytime the enter key is typed inside the box. (Presumably, the user will change the text and then press enter.)
Creating a TextField
You can create a TextField using the following functions:
TextField()
TextField(text, columns, action, color, font)
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str |
'' |
The text to start with. |
columns |
int |
8 |
The width of the field, in characters. |
action |
function |
None |
The function to call when the user presses Enter in the field; it receives one parameter, the field's contents as a string. |
color |
Color |
Color.WHITE |
The field color. |
font |
Font |
None |
The font, for example Font("Serif", Font.ITALIC, 16). If omitted, the default font is used. |
rotation |
int or float |
0 |
How far to turn the field, in degrees, counter-clockwise. |
visibility |
int |
100 |
How visible the field is, from 0 (invisible) to 100 (fully visible). |
For example,
textfield = TextField("type and hit <ENTER> ", 18, processEntry)
where processEntry is a function which expects one parameter, the updated text (a string).
Once created, you can add it to a Display using the Display's add() function.
Functions
Once a TextField has been created, the following functions are available:
| Function | Description |
|---|---|
getText() |
Return the text in the field. |
setText(text) |
Set the text in the field. |
getColor() |
Return the field's background color. |
setColor(color) |
Set the field's background color. |
getFont() |
Return the field's font. |
setFont(font) |
Set the field's font. |
Additionally, the following common functions are available: