#🔒 Tkinter 300x300 window is actually 600x600 on mac retina display

42 messages · Page 1 of 1 (latest)

kind relic
#

Hi when I create a root.geometry("300x300") and i measure the pixels it actually occupates on the screen is a 600x600 pixel square how can I fix this ?

austere ruinBOT
#

@kind relic

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

small flicker
#

What is your screen resolution?

#

@kind relic

kind relic
small flicker
#

Can you post the full code as text please?

kind relic
#

sure ^^

#
from tkinter import *

root = Tk()  # create a root widget
root.title("Tk Example")
root.configure(background="yellow")
root.geometry("300x300")  # width x height + x + y
root.mainloop()

It's nothing rn but this single pixel thing is turning me crazy xd

nimble tusk
#

maybe it's the width of one side and the other's mirrored ?

#

tbh i don't really know, i'm new to python

kind relic
#

wdym I don't quit get it ? ^^

nimble tusk
#

like, maybe the 300x300 width, that, is only the left side, and the other side's mirrored, like the radius of a circle instead of the diameter

kind relic
#

oh ok I see no its "width"x"height"

nimble tusk
#

tbh idk, i'm new

#

it's just a theory

kind relic
#

I think it's a retina problem to counter the massive pixel density but I hate that they do it without asking

small flicker
#

you can make the window resizable using root.resizable(height = True, width = True) as a temporary solution for now

kind relic
#

Yeah ik but I want it fixed xd thats the problem

kind relic
late coyote
#

you could presumably just make it 150x150 if you only care about it being correct on your machine

small flicker
#
w = round(root.winfo_screenwidth() / 12.8)
h = round(root.winfo_screenheight() / 7.2)

root.geometry(f"{w}x{h}")
``` @kind relic
kind relic
#

sorry I wont be able to answer now I need to go to sleep its 5am here ^^

late coyote
#

but yeah if you already know cpp then that's probably fine

late coyote
small flicker
#

they want 300x300, and keep getting 600x600

late coyote
#

sure, but i mean to say the string being generated is 300x300, which is what they already have

small flicker
#

ah true

late coyote
#

which tkinter doesn't seem to be respecting

#

and then on machines that aren't 4k, the dimensions will be wonky because you're hardcoding the divisor

small flicker
#

root.call('tk', 'scaling', 2.0)

late coyote
#

i tried that on my machine, and it didn't seem to actually change the dimensions of the window

small flicker
#

i'm not super knowledgable about tkinter, just googling things

#

trying to be helpful while i wait for my quesiton to be answered

cedar tinsel
blazing leafBOT
cedar tinsel
#

based on their responses, a workaround might look something like: ```py
import subprocess
import sys

IS_RETINA = (
sys.platform == "darwin"
and subprocess.call("system_profiler SPDisplaysDataType | grep -i 'retina'", shell=True) == 0
)

if IS_RETINA:
root.geometry("150x150")
else:
root.geometry("300x300")looks hacky to me though, but i guess it's about the same as what i normally do to fix DPI scaling on windows:py
if sys.platform == "win32":
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(2)```

frosty bay
#

I think the OP needs to answer:

  • what Just_Iced's query about root.winfo_screenwidth etc returns
  • how they're measuring their 600x600 number? eg reported by querying the widget size, physicially measuring on the screen with a rule or some mark-out-rectangle tool ?
  • what the Mac's Display information says about the screen
  • what MacOS they're running, might matter
    Macs with retina displays run a scaled display system by default, with some subpixel dithering stuff to make it possible to present very nice curve edges. Being a nerd, I run in native resoultion via a third party app because I just want max pixels. We need to know, ideally, the physical and logical pixel sizes of their display.
austere ruinBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.