Add an item to the list.
(self, text: str, icon: str = "")
| 201 | self._bind_scroll_events() |
| 202 | |
| 203 | def add_item(self, text: str, icon: str = "") -> None: |
| 204 | """Add an item to the list.""" |
| 205 | display_text = f"{icon} {text}" if icon else text |
| 206 | |
| 207 | item = ctk.CTkButton( |
| 208 | self, |
| 209 | text=display_text, |
| 210 | anchor="w", |
| 211 | height=36, |
| 212 | corner_radius=DIMENSIONS["corner_radius_small"], |
| 213 | fg_color="transparent", |
| 214 | hover_color=COLORS["bg_medium"], |
| 215 | text_color=COLORS["text_primary"], |
| 216 | font=ctk.CTkFont(family=FONTS["family"], size=FONTS["size_normal"]), |
| 217 | command=lambda idx=len(self.items): self._select(idx), |
| 218 | ) |
| 219 | item.pack(fill="x", padx=4, pady=2) |
| 220 | item.bind("<Double-1>", lambda e, idx=len(self.items): self._double_click(idx)) |
| 221 | # Bind scroll events to new item |
| 222 | self._bind_scroll_to_widget(item) |
| 223 | self.items.append(item) |
| 224 | |
| 225 | def _bind_scroll_events(self) -> None: |
| 226 | """Bind mouse wheel scroll events to this scrollable frame.""" |
no test coverage detected