MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / find_element

Method find_element

PySimpleGUI/PySimpleGUI.py:10947–11007  ·  view source on GitHub ↗

Find element object associated with the provided key. THIS METHOD IS NO LONGER NEEDED to be called by the user You can perform the same operation by writing this statement: element = window[key] You can drop the entire "find_element" function name and use [

(self, key, silent_on_error=False, supress_guessing=None, supress_raise=None)

Source from the content-addressed store, hash-verified

10945 return self.find_element(key, silent_on_error=silent_on_error)
10946
10947 def find_element(self, key, silent_on_error=False, supress_guessing=None, supress_raise=None):
10948 """
10949 Find element object associated with the provided key.
10950 THIS METHOD IS NO LONGER NEEDED to be called by the user
10951
10952 You can perform the same operation by writing this statement:
10953 element = window[key]
10954
10955 You can drop the entire "find_element" function name and use [ ] instead.
10956
10957 However, if you wish to perform a lookup without error checking, and don't have error popups turned
10958 off globally, you'll need to make this call so that you can disable error checks on this call.
10959
10960 find_element is typically used in combination with a call to element's update method (or any other element method!):
10961 window[key].update(new_value)
10962
10963 Versus the "old way"
10964 window.FindElement(key).Update(new_value)
10965
10966 This call can be abbreviated to any of these:
10967 find_element = FindElement == Element == Find
10968 With find_element being the PEP8 compliant call that should be used.
10969
10970 Rememeber that this call will return None if no match is found which may cause your code to crash if not
10971 checked for.
10972
10973 :param key: Used with window.find_element and with return values to uniquely identify this element
10974 :type key: str | int | tuple | object
10975 :param silent_on_error: If True do not display popup nor print warning of key errors
10976 :type silent_on_error: (bool)
10977 :param supress_guessing: Override for the global key guessing setting.
10978 :type supress_guessing: (bool | None)
10979 :param supress_raise: Override for the global setting that determines if a key error should raise an exception
10980 :type supress_raise: (bool | None)
10981 :return: Return value can be: the Element that matches the supplied key if found; an Error Element if silent_on_error is False; None if silent_on_error True
10982 :rtype: Element | ErrorElement | None
10983 """
10984
10985 key_error = False
10986 closest_key = None
10987 supress_guessing = supress_guessing if supress_guessing is not None else SUPPRESS_KEY_GUESSING
10988 supress_raise = supress_raise if supress_raise is not None else SUPPRESS_RAISE_KEY_ERRORS
10989 try:
10990 element = self.AllKeysDict[key]
10991 except KeyError:
10992 key_error = True
10993 closest_key = self._find_closest_key(key)
10994 if not silent_on_error:
10995 print('** Error looking up your element using the key: ', key, 'The closest matching key: ', closest_key)
10996 _error_popup_with_traceback('Key Error', 'Problem finding your key ' + str(key), 'Closest match = ' + str(closest_key), emoji=EMOJI_BASE64_KEY)
10997 element = ErrorElement(key=key)
10998 else:
10999 element = None
11000 if not supress_raise:
11001 raise KeyError(key)
11002
11003 if key_error:
11004 if not supress_guessing and closest_key is not None:

Callers 11

mainFunction · 0.95
readMethod · 0.95
FindElementMethod · 0.95
settings_saveMethod · 0.95
settings_restoreMethod · 0.95
set_titleMethod · 0.95
__getitem__Method · 0.95
__init__Method · 0.80
update_weatherMethod · 0.80
_find_targetMethod · 0.80
cprintFunction · 0.80

Calls 3

_find_closest_keyMethod · 0.95
ErrorElementClass · 0.85

Tested by

no test coverage detected