Listbox
A scrollable list of text items.
Example
const lb = app.Listbox({ height: 8 });
lb.insert('end', 'Apple', 'Banana', 'Cherry');
lb.pack.configure({ fill: 'both', expand: true });
lb.bind('<<ListboxSelect>>', () => console.log('selected', lb.curselection()));
Options
| Option | Type | Description |
|---|---|---|
height |
number | Visible rows. |
width |
number | Width in characters. |
selectMode |
string | 'browse', 'single', 'multiple', or 'extended'. |
font |
string | Item font. |
listVariable |
a *Var |
Bind the items to a variable (a list). |
Methods
| Method | Description |
|---|---|
insert(index, ...items) |
Insert items at an index (or 'end'). |
get(first, last?) |
The item(s) at an index / range. |
getItems() |
All items as an array. |
size() |
Number of items. |
delete(first, last?) |
Remove items. |
clear() |
Remove all items. |
curselection() |
Selected indices as an array. |
selectionSet(first, last?) / selectionClear(first, last?) |
Change the selection. |
see(index) / activate(index) |
Scroll to / activate an item. |
Plus the inherited widget methods — see Widget basics.
Events
Selection changes fire <<ListboxSelect>>.
See also
- Treeview — a multi-column / tree alternative