| 351 | self._entry.bind(event, handler) |
| 352 | |
| 353 | class Search_Box(Frame): |
| 354 | def __init__(self, master, button_text="Search", button_ipadx=16, button_background="#009688", button_foreground="white", button_font=None, opacity=0.8, placeholder=None, placeholder_font=None, placeholder_color="grey", entry_highlightthickness=1, entry_width=30, entry_font=None, command=None, ID=None): |
| 355 | Frame.__init__(self, master, ID=ID) |
| 356 | |
| 357 | self._command = command |
| 358 | |
| 359 | self.entry = Metro_Entry(self, width=entry_width, placeholder=placeholder, placeholder_font=placeholder_font, placeholder_color=placeholder_color, highlightthickness=entry_highlightthickness) |
| 360 | self.entry.pack(side=LEFT, fill=BOTH) |
| 361 | |
| 362 | if entry_font: |
| 363 | self.entry.configure(font=entry_font) |
| 364 | |
| 365 | self.button = Metro_Button(self, text=button_text, background=button_background, foreground=button_foreground, font=button_font, command=self._execute_command, padx=button_ipadx) |
| 366 | self.button.pack(side=LEFT, fill=Y) |
| 367 | |
| 368 | if command is not None: |
| 369 | self.entry.bind_entry("<Return>", lambda event: self.button.invoke()) |
| 370 | |
| 371 | def get_text(self): |
| 372 | entry = self.entry |
| 373 | if hasattr(entry, "placeholder_state"): |
| 374 | if entry.placeholder_state.contains_placeholder: |
| 375 | return "" |
| 376 | else: |
| 377 | return entry.get() |
| 378 | else: |
| 379 | return entry.get() |
| 380 | |
| 381 | def set_text(self, text): |
| 382 | entry = self.entry |
| 383 | if hasattr(entry, "placeholder_state"): |
| 384 | entry.placeholder_state.contains_placeholder = False |
| 385 | |
| 386 | entry.delete(0, END) |
| 387 | entry.insert(0, text) |
| 388 | |
| 389 | def clear(self): |
| 390 | self.entry_var.set("") |
| 391 | |
| 392 | def focus(self): |
| 393 | self.entry.focus() |
| 394 | |
| 395 | def _execute_command(self): |
| 396 | text = self.get_text() |
| 397 | self._command(text) |
| 398 | |
| 399 | |
| 400 | class Base_Container(object): |