New capability! __getitem__ added to all ports of PySimpleGUI. Enables skipping the FindElement call

This commit is contained in:
MikeTheWatchGuy 2019-08-17 11:03:36 -04:00
parent fa6f4cc1ce
commit 40abc2e20a
3 changed files with 50 additions and 6 deletions

View file

@ -1,5 +1,5 @@
#usr/bin/python3
version = __version__ = "0.31.0.0 Unreleased"
version = __version__ = "0.31.0.2 Unreleased"
import sys
import types
@ -39,7 +39,7 @@ def TimerStop():
g_time_end = time.time()
g_time_delta = g_time_end - g_time_start
print(g_time_delta)
print(g_time_delta*1000)
###### ##### ##### # # ### # #
# # # # # # # # # ##### # ###### # # # # # # # # ###### #####
@ -3493,6 +3493,21 @@ class Window:
self.MasterFrame.SetSizer(self.OuterSizer)
self.OuterSizer.Fit(self.MasterFrame)
def __getitem__(self, key):
"""
Returns Element that matches the passed in key.
This is "called" by writing code as thus:
window['element key'].Update
:param key: (Any) The key to find
:return: Union[Element, None] The element found or None if no element was found
"""
try:
return self.Element(key)
except Exception as e:
print('The key you passed in is no good. Key = {}*'.format(key))
return None
def __enter__(self):
return self