ScrolledText
Bases: Frame
A text widget with configurable scrollbars and mouse wheel support.
The ScrolledText widget provides a Text widget with scrollbars that can be configured to appear always, never, on hover, or when scrolling. Full mouse wheel support is included.
This widget delegates all Text methods to the internal text widget, so it can be used just like a standard Text widget with additional scrolling functionality.
Attributes:
| Name | Type | Description |
|---|---|---|
vertical_scrollbar |
Scrollbar
|
The vertical scrollbar widget. |
horizontal_scrollbar |
Scrollbar
|
The horizontal scrollbar widget. |
text
property
text: Text
Get the internal text widget.
Returns:
| Type | Description |
|---|---|
Text
|
The underlying Text widget instance. |
__init__
__init__(
master: Optional[Misc] = None,
padding: int = 0,
scroll_direction: Literal[
"horizontal", "vertical", "both"
] = "vertical",
scrollbar_visibility: Literal[
"always", "never", "hover", "scroll"
] = "always",
autohide_delay: int = 1000,
scrollbar_style: str = "default",
**kwargs: Any,
) -> None
Initialize a ScrolledText widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
master
|
Optional[Misc]
|
The parent widget. |
None
|
padding
|
int
|
Padding around the frame container. |
0
|
scroll_direction
|
Literal['horizontal', 'vertical', 'both']
|
Scroll direction - 'vertical', 'horizontal', or 'both'. Use 'both' to enable horizontal scrolling with Shift+MouseWheel. |
'vertical'
|
scrollbar_visibility
|
Literal['always', 'never', 'hover', 'scroll']
|
Scrollbar visibility mode: - 'always': Scrollbars always visible - 'never': Scrollbars hidden (scrolling still works) - 'hover': Scrollbars appear when mouse enters - 'scroll': Scrollbars appear when scrolling, auto-hide after delay |
'always'
|
autohide_delay
|
int
|
Time in milliseconds before auto-hiding scrollbars in 'scroll' mode. |
1000
|
scrollbar_style
|
str
|
The bootstyle for scrollbars (e.g., 'primary', 'success', 'danger'). |
'default'
|
**kwargs
|
Any
|
Additional keyword arguments passed to the Text widget. |
{}
|
Note
Legacy parameters 'autohide', 'vbar', and 'hbar' parameters work, but are deprecated. Use
scroll_direction and scrollbar_visibility instead.
destroy
destroy()
Clean up resources and destroy the widget.
__getattr__
__getattr__(name: str) -> Any
Delegate unknown attribute access to the internal Text widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The attribute name to access. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The attribute from the internal Text widget. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If _text doesn't exist yet or doesn't have the attribute. |