0

I use an another question’s comment function, It has been worked but also makes my Thinker GUI scaling

import ctypes
user32 = ctypes.windll.user32
user32.SetProcessDPIAware()
[w, h] = [user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)]

my question is how to make my GUI recover to normal DPI before I used this function user32.SetProcessDPIAware()

  • This question is discussed [here](https://stackoverflow.com/questions/3129322/how-do-i-get-monitor-resolution-in-python) – Rory May 29 '22 at 18:10
  • Normally if you do `user32.SetProcessDPIAware()` you put a value in the interface and that value will lead to different behavior. See, [MSDN](https://docs.microsoft.com/en-us/windows/win32/api/shellscalingapi/ne-shellscalingapi-process_dpi_awareness#constants) and the [function](https://docs.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-setprocessdpiawareness) you are using, However, tkinter offers you a built in way to get the screen_width and screen_height. Its not clear to me what you have trouble with and why do you think you need these function in a tkinter app. – Thingamabobs May 29 '22 at 18:23
  • @Thingamabobs Yes indeed,Thinter offers funtions like `screenWidth = root.winfo_screenwidth() screenHeight = root.winfo_screenheight()` , However if Windows set scaling it return the error results ,and its trun right when I use user32.SetProcessDPIAware() ,but also effect resolution of my GUI forever – Motoko Kusanagi May 30 '22 at 10:11
  • @diwen have you tried all the values 0,1,2. It sounds like 2 ist the value you are searching for. – Thingamabobs May 30 '22 at 12:40
  • [before use user32.SetProcessDPIAware()][1] [use user32.SetProcessDPIAware()][2] [1]: https://i.stack.imgur.com/RuHu8.jpg [2]: https://i.stack.imgur.com/IROQU.jpg Thank you for your reply, Looking at these screenshots, I just want to get my monitor resolution,but not my GUI. I tried everything I could, I have tried all the values 0,1,2 they affect to my program are same @Thingamabobs – Motoko Kusanagi May 31 '22 at 03:30
  • Please provide a [mre] that includes a tkinter window with that behaviour. – Thingamabobs May 31 '22 at 05:35
  • It works very well when I restart VS Code and rebuild the project, whatever how I set the scaling.I guess `user32.SetProcessDPIAware()` doesn't sense system changes correctly when compiled, Thanks a lot dude~ https://github.com/Weeeendi/Picture2Text/tree/develope This is my repository for this project if you are interested in this project @Thingamabobs – Motoko Kusanagi May 31 '22 at 05:54

0 Answers0