MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / update

Method update

PySimpleGUI/PySimpleGUI.py:2785–2852  ·  view source on GitHub ↗

Changes some of the settings for the Listbox 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 statio

(self, values=None, disabled=None, set_to_index=None, scroll_to_index=None, select_mode=None, visible=None)

Source from the content-addressed store, hash-verified

2783
2784
2785 def update(self, values=None, disabled=None, set_to_index=None, scroll_to_index=None, select_mode=None, visible=None):
2786 """
2787 Changes some of the settings for the Listbox Element. Must call `Window.Read` or `Window.Finalize` prior
2788 Changes will not be visible in your window until you call window.read or window.refresh.
2789
2790 If you change visibility, your element may MOVE. If you want it to remain stationary, use the "layout helper"
2791 function "pin" to ensure your element is "pinned" to that location in your layout so that it returns there
2792 when made visible.
2793
2794 :param values: new list of choices to be shown to user
2795 :type values: List[Any]
2796 :param disabled: disable or enable state of the element
2797 :type disabled: (bool)
2798 :param set_to_index: highlights the item(s) indicated. If parm is an int one entry will be set. If is a list, then each entry in list is highlighted
2799 :type set_to_index: int | list | tuple
2800 :param scroll_to_index: scroll the listbox so that this index is the first shown
2801 :type scroll_to_index: (int)
2802 :param select_mode: changes the select mode according to tkinter's listbox widget
2803 :type select_mode: (str)
2804 :param visible: control visibility of element
2805 :type visible: (bool)
2806 """
2807
2808 if not self._widget_was_created(): # if widget hasn't been created yet, then don't allow
2809 return
2810
2811 if self._this_elements_window_closed():
2812 _error_popup_with_traceback('Error in Listbox.update - The window was closed')
2813 return
2814
2815 if disabled is True:
2816 self.TKListbox.configure(state='disabled')
2817 elif disabled is False:
2818 self.TKListbox.configure(state='normal')
2819 self.Disabled = disabled if disabled is not None else self.Disabled
2820
2821 if values is not None:
2822 self.TKListbox.delete(0, 'end')
2823 for item in list(values):
2824 self.TKListbox.insert(tk.END, item)
2825 # self.TKListbox.selection_set(0, 0)
2826 self.Values = list(values)
2827 if set_to_index is not None:
2828 self.TKListbox.selection_clear(0, len(self.Values)) # clear all listbox selections
2829 if type(set_to_index) in (tuple, list):
2830 for i in set_to_index:
2831 try:
2832 self.TKListbox.selection_set(i, i)
2833 except:
2834 warnings.warn('* Listbox Update selection_set failed with index {}*'.format(set_to_index))
2835 else:
2836 try:
2837 self.TKListbox.selection_set(set_to_index, set_to_index)
2838 except:
2839 warnings.warn('* Listbox Update selection_set failed with index {}*'.format(set_to_index))
2840 if visible is False:
2841 self._pack_forget_save_settings(self.element_frame)
2842 elif visible is True:

Callers

nothing calls this directly

Calls 6

_widget_was_createdMethod · 0.80
insertMethod · 0.80

Tested by

no test coverage detected