[Bug] Rendering frames in scrollable column
Type of Issue (Enhancement, Error, Bug, Question)
Bug
Operating System
Windows
PySimpleGUI Port (tkinter)
Versions
Version information can be obtained by calling sg.main_get_debug_data()
Or you can print each version shown in ()
Python version (3.8.4 (tags/v3.8.4:dfa645a, Jul 13 2020, 16:46:45) [MSC v.1924 64 bit (AMD64)])
PySimpleGUI Version (4.60.3)
GUI Version (tkinter (8.6.9))
Your Experience In Months or Years (optional)
Years Python programming experience 20+ Years Programming experience overall 40+ Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine) yes Anything else you think would be helpful?
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
- [X] Searched main docs for your problem www.PySimpleGUI.org
- [X] Looked for Demo Programs that are similar to your goal. It is recommend you use the Demo Browser! Demos.PySimpleGUI.org
- [ ] If not tkinter - looked for Demo Programs for specific port
- [ ] For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
- [X] Run your program outside of your debugger (from a command line)
- [X] Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
- [X] Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
- [ ] Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released
Detailed Description
The app has a series of rows containing 3 columns of frames containing checkbox objects and buttons inside them with image_data set. When the images get tall, the rendering position of the frames at the end is incorrect.
In the attached example, if the images are 400 pixels tall, images 0-227 are correct, 228 and beyond are all on the same vertical position. When the images are 300 tall, 0-293 are correct. (1st screenshot)
Without the image_data, having 2000 frames, 1-1712 render correctly with 1713 and beyond are all on the same vertical position. (2nd screenshot)
The vertical scroll-bar on the side seems to always be adjusted as if the vertical rows were correctly rendered.
Code To Duplicate
import PySimpleGUI as sg
from PIL import Image, ImageDraw
import io
IMAGES = 300
HEIGHT = 300
def getImage(number):
image = Image.new('RGB', (100, HEIGHT), color=(73, 109, 137))
d = ImageDraw.Draw(image)
d.text((10, 10), str(number), fill=(255, 255, 0))
bio = io.BytesIO()
image.save(bio, format='PNG')
return bio.getvalue()
def buildWindow():
frames = []
for num in range(IMAGES):
imgdta = getImage(num)
box = [[sg.Checkbox("", key="check&&%04d" % num, enable_events=True, visible=False)],
[sg.Button(num, border_width=0,
image_data=imgdta,
key="but&&%04d" % num)]
]
frame = sg.Frame(num, box, key="frame&&%04d" % num, title_color="black")
frames.append(frame)
col = [[fr] for fr in frames]
return [[sg.Column(col, size=(150, 400), scrollable=True, vertical_scroll_only=True, expand_x=True)]]
window = sg.Window("title", buildWindow(), finalize=True, modal=True)
while True:
window, event, values = sg.read_all_windows()
if event in (sg.WIN_CLOSED, None, 'Close (Without Saving)'):
break
The above code demonstrates the problem with a single column.
The code to generate the multi-column GUI is not as simple. I have extracted the GUI bits from the app I am creating and made a "simple" version in the attached zip. That is where the screenshots are from.
Screenshot, Sketch, or Drawing
Watcha Makin?
If you care to share something about your project, it would be awesome to hear what you're building.
an app to pick multiple thumbnail images to be rendered in a higher resolution.
IMO, it is caused by the height of tkinter Canvas widget which used in a scrollable Column element.
It is defined as a signed C short.
Things get a bit funky if you make them larger than 32,000 (strictly 32767, the limit of a signed C
short) particularly at the rendering layer (and definitely don't make the canvas viewport that size!). However, the underlying canvas model uses IEEE doubles to store the coordinates, so there's no reason why you couldn't have things go off that far. You just must keep the size of individual objects down.This is all a legacy of X11, which uses 16-bit values for coordinates and dimensions in quite a few key structures. Changing this > is both logically easy and a lot of work in practice (the assumptions are all over the place).
import PySimpleGUI as sg
from PIL import Image, ImageDraw
import io
IMAGES = 300
HEIGHT = 300
def getImage(number):
image = Image.new('RGB', (100, HEIGHT), color=(73, 109, 137))
d = ImageDraw.Draw(image)
d.text((10, 10), str(number), fill=(255, 255, 0))
bio = io.BytesIO()
image.save(bio, format='PNG')
return bio.getvalue()
frames = []
for num in range(IMAGES):
imgdta = getImage(num)
box = [
#[sg.Checkbox("", key="check&&%04d" % num, enable_events=True, visible=False)],
[sg.Button(num, border_width=0, image_data=imgdta, key="but&&%04d" % num)]
]
frame = sg.Frame(num, box, key="frame&&%04d" % num, title_color="black")
frames.append(frame)
col = [[fr] for fr in frames]
layout = [[sg.Column(col, size=(150, 400), scrollable=True, vertical_scroll_only=True, expand_x=True, expand_y=True, key='Column')]]
window = sg.Window("title", layout, finalize=True, modal=True, resizable=True)
for i, bg in zip((97, 98, 99, 299), ('black', 'white', 'blue', 'yellow')):
w = window["frame&&%04d" % i].widget.master
print(w.winfo_y()) # To confirm each y-ccordinate of each frame correct or not, and it is correct.
window['Column'].widget.canvas.yview_moveto(97/300) # Scroll to 97th item of 300 items
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, None, 'Close (Without Saving)'):
break
window.close()
32398
32732
33066
99866
My suggestion is that you should design your GUI in another way, maybe in pages - refresh the content of each page when required, and it will be much faster to load or start your GUI.
I suspected as much. I was trying to figure out how to get the y coordinate to test this but I didn't know about the .master part of the object.
I think pagination for the view is the way I am going to have to go. Unfortunately, it won't speed things up in the real app as the set of thumbnails are not all the same dimensions and are loaded from files. Pagination would only be used to get around this issue.
Maybe you can refer https://github.com/PySimpleGUI/PySimpleGUI/issues/4953#issuecomment-969166634