support for tkinter backend. tested on windows 11 - #244
Conversation
6d3c0a3 to
76b81aa
Compare
|
Thanks for this! I'm working on an open pr (#227) that changes requires changes to the backends. I'll come back to this pr once that is done. |
|
FYI this PR is ready for review (and compatible with #227) |
almarklein
left a comment
There was a problem hiding this comment.
Thanks for this! I made some comments.
On MacOS this backend is really slow for large resolutions, but there is some room for improvement for the bitmap mode, so this might be improved.
|
I think this addresses everything |
almarklein
left a comment
There was a problem hiding this comment.
There are also some linting errors. Easy to fix: run ruff format and ruff lint to check locally.
The pixel ratio it a bigger problem. If the reported physical size is incorrect, rendering to screen on a hidpi display will error, because the textures don't match size. I spent some time (with help with both tk docs and Claude) trying to get the pixel ratio from tk, but without luck. It may not be possible.
For bitmap mode it's less of a problem, because tk will simply scale the bitmap. Therefore, a quick solution would be to only support bitmap mode, at least for now.
If we do want to support pixel ratio, we'd have to query the OS directly, which involves a different solution for each OS, which gets ugly especially on x11 vs wayland, so I'd rather not go there for this particular backend.
I lifted the logical size computation from matplotlib tk backend (license is permissive PSF/BSD-compatible). |
| # Tk/macOS already works in device pixels for this purpose. | ||
| return 1.0 |
There was a problem hiding this comment.
Unfortunately, this is not the case. (And if it was the case, we'd have to scale width/height in several other places.)
But since on MacOS it already operates in bitmap mode, we basically have the fallback I proposed, but only for MacOS.
Have you been able to test this on a hidpi screen on Windows and/or Linux?
There was a problem hiding this comment.
tested it on windows 11 on the tk_app example
(I have only 1 monitor so I have to logout login between display scale changes)
scaling = 100
resize event : 876 650
winfo: 1000 650
tk scaling: 1.3339898243886428
1 inch: 96.04726735598227
scaling = 150
resize event : 876 650
winfo: 1000 650
tk scaling: 1.332282448377581
1 inch: 95.92433628318584
code used
print("resize event:", event.width, event.height)
print("winfo:", loop._root.winfo_width(), loop._root.winfo_height())
print("tk scaling:", loop._root.tk.call("tk", "scaling"))
print("1 inch:", loop._root.winfo_fpixels("1i"))it seems windows automatically scales dpi-unaware processes
So behavior is probably fine on windows
added support for tkinter backend.


tested the PR a bunch on my local machine (windows 11)
feedback from X11 / XWayland is welcome
Disclaimer : I used AI, though I nitpicked it to death for maintainability / respect to the repo's coding style
I would understand if you told me to eat sh** nonethelessCONTRIBUTING.md seems to allow responsible vibe coding. Yay !