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.
| raise ValueError(f"Unsupported bitmap format {format!r}") | ||
|
|
||
| try: | ||
| rgba = np.asarray(memoryview(data)) |
There was a problem hiding this comment.
Not a big thing, but just slightly shorter.
| rgba = np.asarray(memoryview(data)) | |
| rgba = np.asarray(data) |
| if isinstance(self.master, _RenderToplevel): | ||
| self.master.geometry(f"{width}x{height}") | ||
| else: | ||
| self.configure(width=width, height=height) |
There was a problem hiding this comment.
Do you know what configuring the width and height does? I could not find it. Would be good to add that as a comment.
There was a problem hiding this comment.
geometry() asks the window manager to resize the enclosing Toplevel/window to that size.
configure() set the widget requested size
| def set_title(self, title: str) -> None: | ||
| self.root.title(title) |
There was a problem hiding this comment.
The pattern to follow is to implement _rc_set_title() on the widget, which then does something like:
if isinstance(self.master, _RenderToplevel):
self.master.root.title(title)
I lifted the logical size computation from matplotlib tk backend (license is permissive PSF/BSD-compatible). |
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 !