Listbox#
Listbox is tkinter’s list of selectable text lines (tk.Listbox), themed
by ttkbootstrap. Lines are addressed by integer index (0-based) or the special
index "end" / "active". This page is the complete reference for its own
options and methods; the shared widget methods are under
Capabilities.
Options#
Option |
Type |
Description |
|---|---|---|
|
|
Constructor only. |
|
|
A |
|
|
|
|
|
The background color of selected lines. |
|
|
The text color of selected lines. |
|
|
The border width of selected lines, in pixels. |
|
|
How the active line is marked: |
|
|
Whether the selection is exported to the X selection / clipboard. |
|
|
The font for the lines. |
|
|
The text color. |
|
|
The surface color. |
|
|
The text color when |
|
|
Line alignment: |
|
|
The requested width in characters ( |
|
|
The requested height in lines ( |
|
|
The 3-D border width in pixels. |
|
|
The border style: |
|
|
The width of the focus highlight around the widget. |
|
|
The focus-highlight color when the widget has focus. |
|
|
The focus-highlight color when the widget does not have focus. |
|
|
|
|
|
The mouse cursor (see Cursors). |
|
|
Whether the listbox accepts keyboard focus during traversal. |
|
|
Whether the window resizes in whole lines/characters. |
|
|
A callback connecting the listbox to a horizontal scrollbar. |
|
|
A callback connecting the listbox to a vertical scrollbar. |
Methods#
Content#
- insert(index, *elements)
Insert one or more lines before
index.- Parameters:
index – the position, or
"end"to append.elements – the strings to add.
- Returns:
None.
- delete(first, last=None)
Delete the lines from
firstthroughlast(or a single line).- Returns:
None.
- get(first, last=None)
Return the text of a line, or a tuple of lines over a range.
- size()
Return the number of lines.
- Return type:
Indices#
- index(index)
Resolve an index expression to an integer line number.
- Return type:
- nearest(y)
Return the index of the visible line nearest a y pixel coordinate.
- Return type:
- see(index)
Scroll so the line at
indexis visible.- Returns:
None.
- activate(index)
Make the line at
indexthe active one (the keyboard-navigation cursor).- Returns:
None.
Selection#
- selection_set(first, last=None)
Select a line, or a range of lines. Alias:
select_set.- Returns:
None.
- selection_clear(first, last=None)
Deselect a line or range. Alias:
select_clear.- Returns:
None.
- selection_includes(index)
Report whether the line at
indexis selected. Alias:select_includes.- Return type:
- selection_anchor(index)
Set the selection anchor — the fixed end of a range selection. Alias:
select_anchor.- Returns:
None.
Per-line appearance#
- itemconfigure(index, **options)
Set (or query) the appearance of one line. Alias:
itemconfig.- Parameters:
options –
background,foreground,selectbackground,selectforeground.- Returns:
the option spec when queried with a single option name, else
None.
- itemcget(index, option)
Return one per-line option.
Scrolling#
- yview(*args)
Query or set the vertical view; usually wired to a scrollbar via
yscrollcommand.xviewis the horizontal counterpart, and both have*_moveto(fraction)and*_scroll(number, what)variants.- Returns:
with no args, the visible fraction
(first, last); elseNone.- Return type:
tuple | None
- scan_mark(x, y)
Record a starting point for a fast drag-scroll.
- Returns:
None.
- scan_dragto(x, y)
Scroll the view relative to the
scan_markpoint.- Returns:
None.
See also#
Tk listbox manual page — the canonical upstream reference (Tcl 8.6).