Changes some of the settings for the OptionMenu Element. Must call `Window.Read` or `Window.Finalize` prior Changes will not be visible in your window until you call window.read or window.refresh. If you change visibility, your element may MOVE. If you want it to remain st
(self, value=None, values=None, disabled=None, visible=None, size=(None, None))
| 2572 | text_color=fg, key=key, pad=pad, tooltip=tooltip, visible=visible, metadata=metadata) |
| 2573 | |
| 2574 | def update(self, value=None, values=None, disabled=None, visible=None, size=(None, None)): |
| 2575 | """ |
| 2576 | Changes some of the settings for the OptionMenu Element. Must call `Window.Read` or `Window.Finalize` prior |
| 2577 | |
| 2578 | Changes will not be visible in your window until you call window.read or window.refresh. |
| 2579 | |
| 2580 | If you change visibility, your element may MOVE. If you want it to remain stationary, use the "layout helper" |
| 2581 | function "pin" to ensure your element is "pinned" to that location in your layout so that it returns there |
| 2582 | when made visible. |
| 2583 | |
| 2584 | :param value: the value to choose by default |
| 2585 | :type value: (Any) |
| 2586 | :param values: Values to be displayed |
| 2587 | :type values: List[Any] |
| 2588 | :param disabled: disable or enable state of the element |
| 2589 | :type disabled: (bool) |
| 2590 | :param visible: control visibility of element |
| 2591 | :type visible: (bool) |
| 2592 | :param size: (width, height) size in characters (wide), height is ignored and present to be consistent with other elements |
| 2593 | :type size: (int, int) (width, UNUSED) |
| 2594 | """ |
| 2595 | if not self._widget_was_created(): # if widget hasn't been created yet, then don't allow |
| 2596 | return |
| 2597 | |
| 2598 | if self._this_elements_window_closed(): |
| 2599 | _error_popup_with_traceback('Error in OptionMenu.update - The window was closed') |
| 2600 | return |
| 2601 | |
| 2602 | if values is not None: |
| 2603 | self.Values = values |
| 2604 | self.TKOptionMenu['menu'].delete(0, 'end') |
| 2605 | |
| 2606 | # Insert list of new options (tk._setit hooks them up to var) |
| 2607 | # self.TKStringVar.set(self.Values[0]) |
| 2608 | for new_value in self.Values: |
| 2609 | self.TKOptionMenu['menu'].add_command(label=new_value, command=tk._setit(self.TKStringVar, new_value)) |
| 2610 | if value is None: |
| 2611 | self.TKStringVar.set('') |
| 2612 | |
| 2613 | if size == (None, None): |
| 2614 | max_line_len = max([len(str(l)) for l in self.Values]) if len(self.Values) else 0 |
| 2615 | if self.AutoSizeText is False: |
| 2616 | width = self.Size[0] |
| 2617 | else: |
| 2618 | width = max_line_len + 1 |
| 2619 | self.TKOptionMenu.configure(width=width) |
| 2620 | else: |
| 2621 | self.TKOptionMenu.configure(width=size[0]) |
| 2622 | |
| 2623 | if value is not None: |
| 2624 | self.DefaultValue = value |
| 2625 | self.TKStringVar.set(value) |
| 2626 | |
| 2627 | if disabled is True: |
| 2628 | self.TKOptionMenu['state'] = 'disabled' |
| 2629 | elif disabled is False: |
| 2630 | self.TKOptionMenu['state'] = 'normal' |
| 2631 | self.Disabled = disabled if disabled is not None else self.Disabled |
nothing calls this directly
no test coverage detected