#🔒 Tkinter 300x300 window is actually 600x600 on mac retina display
42 messages · Page 1 of 1 (latest)
@kind relic
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.
4k
Can you post the full code as text please?
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
maybe it's the width of one side and the other's mirrored ?
tbh i don't really know, i'm new to python
wdym I don't quit get it ? ^^
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
oh ok I see no its "width"x"height"
I think it's a retina problem to counter the massive pixel density but I hate that they do it without asking
retina problem ?
you can make the window resizable using root.resizable(height = True, width = True) as a temporary solution for now
Yeah ik but I want it fixed xd thats the problem
To much pixel density/resolution on a retina screen in 4k
you could presumably just make it 150x150 if you only care about it being correct on your machine
w = round(root.winfo_screenwidth() / 12.8)
h = round(root.winfo_screenheight() / 7.2)
root.geometry(f"{w}x{h}")
``` @kind relic
yeah but on other machine it wouldnt work its horrible Ill end up coding a gui in c++ for a dumb project xd
sorry I wont be able to answer now I need to go to sleep its 5am here ^^
you can just check whether the current machine has 4k display and choose the constant based on that
but yeah if you already know cpp then that's probably fine
on the 4k machine, this will still give you 300x300 (i.e. the wrong dimensions), no? and then on other machines it'll give the wrong number. on my machine it's 118x136
they want 300x300, and keep getting 600x600
sure, but i mean to say the string being generated is 300x300, which is what they already have
ah true
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
root.call('tk', 'scaling', 2.0)
i tried that on my machine, and it didn't seem to actually change the dimensions of the window
i'm not super knowledgable about tkinter, just googling things
trying to be helpful while i wait for my quesiton to be answered
asweigart/pyautogui#33
https://stackoverflow.com/q/58349657
supposedly it is an issue specific to retina displays where apps aren't informed of the real screen resolution, so i guess you have to check for it yourself?
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)```
I think the OP needs to answer:
- what Just_Iced's query about
root.winfo_screenwidthetc 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.
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.