Skip to content

Instantly share code, notes, and snippets.

@YoomamaFTW
Last active August 16, 2019 02:28
Show Gist options
  • Save YoomamaFTW/2bc738bdafe3e4bc4b5f2373c7ea9490 to your computer and use it in GitHub Desktop.
Save YoomamaFTW/2bc738bdafe3e4bc4b5f2373c7ea9490 to your computer and use it in GitHub Desktop.
Mac users with PySimpleGUI, use the following padding for correct scrollable window
'''
As of August 15, 2019, using Python 3.7.4, PySimpleGUI == 4.1.0, macOS 10.14.6, macOS users will have trouble using scrolling or scrollable windows if you are using the Column layout method. The issue is a large portion of the bottom is unable to be in view, unless the user manually resizes the window by at least a few pixels.
EDIT: The formula works for any layering of elements in a scrollable window! So you can have a row with Text, a row with multiline, a row with buttons. It does not matter. The formula always works!
TL;DR Just add a final element in your layer with top padding like so:
layer += [sg.Text("Whatever you want. Maybe copyright", pad=(0, (22.5 * NUMBER_OF_ROWS - 13.0357, 0)))]
NUMBER_OF_ROWS, not number of elements.
The fix is to add a huge white space with the Text element (i.e. use padding). For example (please don't use this in production):
'''
layer = []
for i, x in enumerate(range(25)):
layer += [
[sg.Text(text=("Row: " + str(i + 1))), sg.Multiline()]
]
layer += [[sg.Text(text="Copyright 2019 YoomamaFTW", pad=(0, (450, 0))]]
'''
I've found that the compatibility issue with macOS and PySimpleGUI with Python3.7 regarding window sizes and the content being unable to be "snug fit" can be resolved using a simple linear functions.
Yes, the padding is a simple y=mx+b function.
Here is the function you'll need to calculate the padding: y = 22.5 * yourVariable - 13.0357 (you can leave out the decimal points).
Issue is based on: https://github.com/PySimpleGUI/PySimpleGUI/issues/1812
The following is:
1) The function with the algorithm to identify how much padding is needed
2) The window used for testing
'''
# 1
import PySimpleGUI as sg
def mainload():
number_of_repeats = 25 # Change this number to your liking
layout = []
for x in range(number_of_repeats):
layout += [
[sg.Text("New input", sg.Multiline()] # The below formula is dedicated to multiline only
]
top_padding = 22.5 * number_of_repeats - 13.0357
layout += [
[sg.Text("Whatever you want", pad=(0, (top_padding, 0))]
]
win_main = sg.Window("Your title", resizable=True) \
.Layout([[sg.Column(layout-layout, scrollable=True)]])
while True:
event, value = win_main.Read()
if __name__ == '__main__':
mainload()
# 2
import PySimpleGUI as sg
def mainload():
abc = 'abc'
layout = [
[sg.Text(text="Alrighty, testing")],
[sg.OK()]
]
for i, x in enumerate(range(49)):
layout += [
[sg.Text("New line: " + str(i + 1)), sg.Multiline()]
]
layout += [
[sg.Text("White space (can also be made into copyright space :P. Food for thought.)", pad=(0, (1070, 0)))]
]
win_main = sg.Window("Stay Hydrated | Register", resizable=True) \
.Layout([[sg.Column(layout=layout, scrollable=True)]])
while True:
event, value = win_main.Read()
if __name__ == '__main__':
mainload()
@YoomamaFTW
Copy link
Author

EDIT: The formula works for any layering of elements in a scrollable window! So you can have a row with Text, a row with multiline, a row with buttons. It does not matter. The formula always works!
TL;DR Just add a final element in your layer with top padding like so:

layer += [sg.Text("Whatever you want. Maybe copyright", pad=(0, (22.5 * NUMBER_OF_ROWS - 13.0357, 0)))]
NUMBER_OF_ROWS, not number of elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment