From 5cd4965d2a8ba31493be97ac73da0a05f5fa2b93 Mon Sep 17 00:00:00 2001 From: Orsiris de Jong Date: Thu, 3 Jan 2019 09:26:12 +0100 Subject: [PATCH] Allow to silently skip no found elements --- PySimpleGUI.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index 01542bfd..a40d8e73 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -3735,15 +3735,18 @@ class Window: FillFormWithValues(self, values_dict) return self - def FindElement(self, key): + def FindElement(self, key, silent_on_error=None): element = _FindElementFromKeyInSubForm(self, key) if element is None: - print('*** WARNING = FindElement did not find the key. Please check your key\'s spelling ***') - PopupError('Keyword error in FindElement Call', - 'Bad key = {}'.format(key), - 'Your bad line of code may resemble this:', - 'window.FindElement("{}")'.format(key)) - return ErrorElement(key=key) + if not silent_on_error == True: + print('*** WARNING = FindElement did not find the key. Please check your key\'s spelling ***') + PopupError('Keyword error in FindElement Call', + 'Bad key = {}'.format(key), + 'Your bad line of code may resemble this:', + 'window.FindElement("{}")'.format(key)) + return ErrorElement(key=key) + else: + return False return element Element = FindElement # Shortcut function