Pysimplegui: [Bug] Save Image does not work correctly after change of screen resolution

Created on 3 Jun 2020  ·  4Comments  ·  Source: PySimpleGUI/PySimpleGUI

Type of Issues (Bug, Question)

Windows 10 1909

Python 3.7.4

PySimpleGUI 4.15.2


4.15.2 Released 15-Jan-2020

This is critical to know. Knowing where your PySimpleGUI.py file is located is just as important. You can get these by adding this to the top of your file and running it:

import PySimpleGUI as sg
print(sg)
print(sg.version)

Your Experience Levels In Months or Years

____2y_____ Python programming experience
_________ Programming experience overall
____yes_____ Have used another Python GUI Framework (tkinter, Qt, etc) previously (yes/no is fine)?

You have completed these steps:

  • [x ] Read instructions on how to file an Issue
  • [x ] Searched through main docs http://www.PySimpleGUI.org for your problem
  • [ ] Searched through the readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • [x ] Looked for Demo Programs that are similar to your goal http://www.PySimpleGUI.com
  • [ ] Note that there are also Demo Programs under each port on GitHub
  • [ ] Run your program outside of your debugger (from a command line)
  • [x ] Searched through Issues (open and closed) to see if already reported

Description of Problem / Question / Details

I used the code of the program https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Save_Window_As_Image.py to save my images as PNG Files. This works fine.
The problem occurs after I increased the screen resolution from 1360x768 to 1920x1080 to save larger images. Only part of the image was saved. The same problem occurs with the demo program:
grafik
original screen resolution 1360x768:
grafik
Going to lower resolution than original seems to work
My question is: what part of python do I have to reinstall in order to make the script working again?

Otherwise I am very satisfied with PySimpleGUI, see https://meteorspectroscopy.org/2020/03/27/meteor-spectra-analysis-new-version/ for a description of my script based on it

Code To Duplicate

Demo_Save_Window_As_Image.py see above

Demo Programs

Most helpful comment

@Jason,

thanks a lot for your advice. I added the two lines to my code and it works for all resolutions.

That is what I like about PySimpleGUI: I always get solutions to my problems. Also very quick response. Great!

Martin
grafik

All 4 comments

Demo programs provide 2 functions. They provide design patterns / examples of how to use specific PySimpleGUI features or functions. The other thing they do is demonstrate ways of integrating your application with other packages or libraries. They're not meant to be full-blown applications but as implied, demos. I'm not a PIL expert so I don't know how to advise you on how to best solve your problem using the PIL package.

The Meteor Spectra Analysis program is quite impressive!

Sometime I also have problems on resolution of display. It is not caused by PySimpleGUI, but tkinter.

Function TkWinDisplayChanged in tkinter uses the windows API call GetDeviceCaps to get the screen width and height with the parameters HORZRES and VERTRES.

In GetDeviceCaps, there's note:

GetDeviceCaps reports info that the display driver provides. If the display driver declines to report any info, GetDeviceCaps calculates the info based on fixed calculations. If the display driver reports invalid info, GetDeviceCaps returns the invalid info. Also, if the display driver declines to report info, GetDeviceCaps might calculate incorrect info because it assumes either fixed DPI (96 DPI) or a fixed size (depending on the info that the display driver did and didn’t provide). Unfortunately, a display driver that is implemented to the Windows Display Driver Model (WDDM) (introduced in Windows Vista) causes GDI to not get the info, so GetDeviceCaps must always calculate the info.

It means the result is not trusted, so most of time, I add this into my script before where tkinter used, and most of time it work fine. Not to switch reslution when python or tkinter running, some values will be stored and kept unchanged.

import ctypes
ctypes.windll.user32.SetProcessDPIAware()   # Set unit of GUI to pixels

Perhaps you can try it.

@Jason,

thanks a lot for your advice. I added the two lines to my code and it works for all resolutions.

That is what I like about PySimpleGUI: I always get solutions to my problems. Also very quick response. Great!

Martin
grafik

This one is all @jason990420 !!! WOW, Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Was this page helpful?
0 / 5 - 0 ratings