DropdownButton
Bases: MenuButton
context_menu
property
context_menu
Returns the context menu widget
__init__
__init__(
master: Master = None,
text: Any = None,
items: list[ContextMenuItem] = None,
**kwargs: Unpack[DropdownButtonKwargs],
)
Create a dropdown button backed by a ContextMenu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
master
|
Master
|
Parent widget. If None, uses the default root window. |
None
|
text
|
str
|
Label text for the button. |
None
|
items
|
list
|
Initial list of ContextMenuItem entries. |
None
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
command |
Callable
|
Callback when the button is activated. |
image |
PhotoImage
|
Tk image to display. |
icon |
str | dict
|
Bootstyle icon spec for the button content. |
icon_only |
bool
|
Whether to reserve label padding when showing only an icon. |
compound |
str
|
Placement of image relative to text. |
padding |
int | tuple
|
Extra padding around the button content. |
density |
str
|
The vertical and horizontal compactness of widget content, e.g. 'default', 'compact'. |
width |
int
|
Width of the button. |
underline |
int
|
Index of underlined character in text. |
state |
str
|
Widget state ('normal', 'active', 'disabled', 'readonly'). |
takefocus |
bool
|
Participation in focus traversal. |
style |
str
|
Explicit ttk style name. |
textvariable |
Variable
|
Existing Tk variable for the label text. |
textsignal |
Signal[str]
|
Signal bound to the textvariable. |
accent |
str
|
Accent token for styling (e.g., 'primary', 'danger'). |
variant |
str
|
Style variant (e.g., 'outline', 'ghost'). |
bootstyle |
str
|
DEPRECATED - Use |
surface |
str
|
Surface token for style. |
style_options |
dict
|
Dict forwarded to the menubutton style builder. |
popdown_options |
dict
|
Dict forwarded to ContextMenu (e.g., anchor, attach, offset). |
show_dropdown_button |
bool
|
Show/hide the chevron. |
dropdown_button_icon |
str | dict
|
Icon name for the chevron. |
on_item_click
on_item_click(callback: Callable) -> None
Set item click callback. Callback receives item_info = {'type': str, 'text': str, 'value': Any}.
off_item_click
off_item_click() -> None
Remove the item click callback.
show_menu
show_menu()
Show the dropdown menu unless disabled or readonly.