Screen resolution according to tkinter and PIL?

91 Views Asked by At

According to tkinter my screen has (1536x864)px while according to PIL my screen has (1920x1080)px, what is going on here and is there a way to solve this?

So I was writing a little program that makes a transparent tkinter window that i can move arround. When I press a button, the program uses the winfo.rootx, winfo_rooty, width and height to calculate where the four edges of the frame are. These are then passed to PIL ImageGrab.grab for it to screenshot the window.

    def capture(self,event=None):
        self.update()
        x0 = self.winfo_rootx() #left wall
        y0 = self.winfo_rooty() #top wall
        x1 = x0 + self.width #right wall
        y1 = y0 + self.height #bottom wall
        img = ImageGrab.grab(bbox=(x0,y0,x1,y1))

When I had the tkinter window in the top left, the plot was perfect, however when I moved the window over towards the bottom right, it captured a rectangle, different from my tkinter frame.

It must be about 2hours later that I noticed what was wrong: according to tkinter my screen has (1536x864)px while according to PIL my screen has (1920x1080)px. What is going on here?

Correct image top left: Red is the frame that is capturing, blue is the captured frame. Correct image top left

Wrong image bottom right: Red is the frame that is capturing, blue is the captured frame: Wrong image bottom right

I managed to fix this by adding a factor 1920/1536=1.25 so that the output of tkinter gets upscaled to use as input to PIL.

0

There are 0 best solutions below