Skip to content
Permalink
Browse files

New Element method!! expand(expand_x, expand_y). Paramters are bools.

  • Loading branch information...
PySimpleGUI PySimpleGUI
PySimpleGUI authored and PySimpleGUI committed Oct 6, 2019
1 parent 48eea54 commit b9a161acc5e9b86dbb397f3556a3d81af0640f79
Showing with 54 additions and 2 deletions.
  1. +54 −2 PySimpleGUI.py
@@ -1,5 +1,5 @@
#!/usr/bin/python3
version = __version__ = "4.5.0.22 Unreleased Mac Buttons. Element size get/set. Screen Size. hide/unhide row. Button rebinding"
version = __version__ = "4.5.0.23 Unreleased Mac Buttons. Element size get/set. Screen Size. hide/unhide row. Button rebinding. Element.expand"


# 888888ba .d88888b oo dP .88888. dP dP dP
@@ -772,7 +772,9 @@ def SetFocus(self, force=False):
def set_size(self, size=(None, None)):
"""
Changes the size of an element to a specific size.
:param size: Tuple[int, int] The size in characters, rows typically
It's possible to specify None for one of sizes so that only 1 of the element's dimensions are changed.
:param size: Tuple[int, int] The size in characters, rows typically. In some cases they are pixels
"""
try:
if size[0] != None:
@@ -785,7 +787,12 @@ def set_size(self, size=(None, None)):
except:
print('Warning, error setting height on element with key=', self.Key)


def get_size(self):
"""
Return the size of an element in Pixels. Care must be taken as some elements use characters to specify their size but will return pixels when calling this get_size method.
:return: Tuple[int, int] - Width, Height of the element
"""
try:
w = self.Widget.winfo_width()
h = self.Widget.winfo_height()
@@ -801,12 +808,33 @@ def hide_row(self):
except:
print('Warning, error hiding element row for key =', self.Key)


def unhide_row(self):
try:
self.ParentRowFrame.pack()
except:
print('Warning, error hiding element row for key =', self.Key)

def expand(self, expand_x=False, expand_y=False):
"""
Causes the Element to expand to fill available space in the X and Y directions. Can specify which or both directions
:param expand_x: (Bool) If True Element will expand in the Horizontal directions
:param expand_y: (Bool) If True Element will expand in the Vertical directions
"""

if expand_x and expand_y:
fill = tk.BOTH
elif expand_x:
fill = tk.X
elif expand_y:
fill = tk.Y
else:
return

self.Widget.pack(expand=True, fill=fill)
self.ParentRowFrame.pack(expand=True, fill=fill)


def __call__(self, *args, **kwargs):
"""
@@ -2096,6 +2124,29 @@ def Get(self):
return self._TKOut.output.get(1.0, tk.END)


def expand(self, expand_x=False, expand_y=False):
"""
Causes the Element to expand to fill available space in the X and Y directions. Can specify which or both directions
:param expand_x: (Bool) If True Element will expand in the Horizontal directions
:param expand_y: (Bool) If True Element will expand in the Vertical directions
"""

if expand_x and expand_y:
fill = tk.BOTH
elif expand_x:
fill = tk.X
elif expand_y:
fill = tk.Y
else:
return

self._TKOut.output.pack(expand=True, fill=fill)
self._TKOut.frame.pack(expand=True, fill=fill)
self.ParentRowFrame.pack(expand=True, fill=fill)



set_focus = Element.SetFocus
set_tooltip = Element.SetTooltip
tk_out = TKOut
@@ -5663,6 +5714,7 @@ def Finalize(self):
except:
self.TKrootDestroyed = True
Window.DecrementOpenCount()
print('** Finalize failed **')
# _my_windows.Decrement()
# return None, None
return self

0 comments on commit b9a161a

Please sign in to comment.
You can’t perform that action at this time.