Tkinter-Designer icon indicating copy to clipboard operation
Tkinter-Designer copied to clipboard

DPI Awareness, wrong scaling

Open kroomz opened this issue 3 years ago • 17 comments

The generated file (and gui.py itself) don't have any DPI awareness.

Unfortunately ctypes.windll.shcore.SetProcessDpiAwareness(1) (which works on many other UIs) breaks the design.

So on my device which has a DPI of 1:2.5 the application will either look blurry and therefore cheap, or with ctypes the application will shrink and break txt, entrys and btns.

-> Maybe export the image files as vector and set dynamic sizing?

kroomz avatar Oct 16 '22 10:10 kroomz

Default on Device with 1:2 DPI (blurry!)

image

DPI Awareness set with ctypes on device with 1:2 DPI (broken sizes!)

image

kroomz avatar Oct 16 '22 10:10 kroomz

Hey @kroomz , What do you mean by exporting images as vector?

ParthJadhav avatar Oct 17 '22 13:10 ParthJadhav

Hey @kroomz , What do you mean by exporting images as vector?

Vector images are basically a file that can scale infinitely, as it doesn't have any rendered data hard coded it renders the image on the fly, they generally have extensions like .svg (scalable vector graphic) etc. more on that here

Why should you use it? The point is to have responsiveness. as if a frame needs 10px X 10px it is going to render itself as 10px X 10 px same goes for 100 if not 1000's pixels.

rohanbatrain avatar Oct 29 '22 05:10 rohanbatrain

-> Maybe export the image files as vector and set dynamic sizing?

By that I guess the OP means, use .svg instead of .png of .jpeg in your code.

rohanbatrain avatar Oct 29 '22 05:10 rohanbatrain

Yes, I know what vectors are 😄 But I was confused with what will happen to actual Images which are imported to Figma.

Either way the suggestion would work great on Buttons & Text Boxes etc. And let's implement it.

But do you have any ideas about what should we do do with Actual Images for scaling? Figma has a option for exporting images at different scales (1x, 2x)...

@rohanbatrain @kroomz

ParthJadhav avatar Oct 29 '22 05:10 ParthJadhav

Yes, I know what vectors are smile But I was confused with what will happen to actual Images which are imported to Figma.

Either way the suggestion would work great on Buttons & Text Boxes etc. And let's implement it.

But do you have any ideas about what should we do do with Actual Images for scaling? Figma has a option for exporting images at different scales (1x, 2x)...

@rohanbatrain @kroomz

Sorry it wasn't clear in your question that you know vectors or not :smiley: , anyways I would not suggest you to go with figma api calls for different scales, as you would be limited on X sizes on doubles, like 1x 2x as mentioned by you already, why not resize them locally using PIL library? But how are we going to know what sizes to dynamically pass to PIL? That's a problem to think of

rohanbatrain avatar Oct 29 '22 05:10 rohanbatrain

If we can get to know what screen sizes we are aiming for displaying the program, then we can use these values to generate a ready to use template and pass that to PIL, and then PIL would resize images and pass it to Tkinter UI. what does this mean? It mean we would have to test this tool and build some preset that if the display is 1920x1080 then use X present, passing that X present to PIL will resize the images accordingly.

Practical approach,

  1. if we are rendering for 1080p then preset would resize images for 1080p (using PIL)
  2. and same for 1920, 2160 etc etc

rohanbatrain avatar Oct 29 '22 05:10 rohanbatrain

It may require some tweaking and testing. Would not suggest to directly dive into production with this suggestion.

rohanbatrain avatar Oct 29 '22 05:10 rohanbatrain

and by the way, kudos for releasing such a great code, and that of under BSD license, Hats OFF dude :+1:

rohanbatrain avatar Oct 29 '22 05:10 rohanbatrain

Sorry it wasn't clear in your question that you know vectors or not 😃

HAHA, Now that I rechecked what my question was, it seems that's what it meant. Sorry for unclear question.

anyways I would not suggest you to go with figma api calls for different scales, as you would be limited on X sizes on doubles, like 1x 2x as mentioned by you already, why not resize them locally using PIL library? But how are we going to know what sizes to dynamically pass to PIL? That's a problem to think of

Practical approach, if we are rendering for 1080p then preset would resize images for 1080p (using PIL) and same for 1920, 2160 etc etc

Sounds good... We just need to create a table with resizing scale needed for different standard display sizes. We also need to think about text. If you check the Image shared by OP u can see that even the text needs to be scaled. What do you think?

and by the way, kudos for releasing such a great code, and that of under BSD license, Hats OFF dude 👍

Thanks @rohanbatrain 😄

ParthJadhav avatar Oct 29 '22 11:10 ParthJadhav

HAHA, Now that I rechecked what my question was, it seems that's what it meant. Sorry for unclear question.

Not a big deal, happens all the time, it's alright.

Sounds good... We just need to create a table with resizing scale needed for different standard display sizes. We also need to think about text. If you check the Image shared by OP u can see that even the text needs to be scaled. What do you think?

For this, in my opinion we need to fetch the size of the window tkinter is rendering, and then through a function which would change font size accordingly. For ex:

If a user started resizing window we would start fetching the height and weight and then accordingly change the font, this is the only thing i can think of right now about text.

rohanbatrain avatar Oct 29 '22 13:10 rohanbatrain

I guess that's a good idea, I'll look into it. Or let me know if you want to work on it

ParthJadhav avatar Nov 02 '22 04:11 ParthJadhav

Thanks @rohanbatrain

ParthJadhav avatar Nov 02 '22 04:11 ParthJadhav

I guess that's a good idea, I'll look into it. Or let me know if you want to work on it

Sure i would love to but right now i am having CBSE BOARDSS EXAMS !!! :( You know the pressure right!

I would be looking into this if possible in 2023. Until i hope the community could find that out somehow.

rohanbatrain avatar Nov 05 '22 19:11 rohanbatrain

Good Luck for the exams @rohanbatrain 😄 I actually don't know the pressure :) I was passed without any examinations due to lockdown. Lucky me 😄

ParthJadhav avatar Nov 06 '22 06:11 ParthJadhav

I'll work on it if I get time...

ParthJadhav avatar Nov 06 '22 06:11 ParthJadhav

Good Luck for the exams @rohanbatrain smile I actually don't know the pressure :) I was passed without any examinations due to lockdown. Lucky me smile

Oh yeah, understandable as my 10th result got wrecked because of COVID, haha anyways now that is gone its time for my 12th, which has to be good. Also thanks for the wishes buddy. Hearty appreciated them :heart:

rohanbatrain avatar Nov 14 '22 17:11 rohanbatrain