When geometries (e.g. an oval) on a tkinter Canvas widget are changed (e.g. moved), the Canvas is not redrawn on Mac OS. The following two code snippets reproduce the issue on Mac OS.
Expected behavior: One should see a circle moving from the top-left of the window/canvas to the right.
Actual behavior: In some cases, the circle is not even drawn in its initial position. In most cases, however, the circle is drawn in its initial position but does not "move" anywhere. While the Canvas does not change visually, the update function / _update method in both examples does in fact get called repeatedly as one would expect.
Variations: A call to the Canvas's update_idletasks method (as commented out in my examples) may cause (or actually prohibit) the circle being drawn in its initial position. In theory (and on other operating systems), this call should not be necessary.
"Workaround": The exact same code works on various flavors of Linux and Windows and apparently on "older" versions of Mac OS (see below).
Context: I first saw this issue with a bunch of university students and their Mac Books. I do not own a Mac Book so I had to gather this info (and confirmation of the above mentioned behavior) from various Mac Book owners.
Hardware: Mac Books, both M1-based and x86-based (dating as far back as 2017)
Operating System: Mac OS 12.3 definitely. It appears that Mac OS 11.x is not affected - still seeking confirmation on this one.
CPython versions: 3.8, 3.9, 3.10 (various micro-versions of each of them)
CPython distribution: conda-forge
CPython architectures: Recent (at least past ~2 months) x86-builds, both on x86 CPUs and on Rosetta on M1, plus recent ARM-builds on M1 definitely. It appears that x86 builds older than one year yield better (yet not completely deterministic) results - still seeking confirmation on this one, too.
tkinter version: 8.6.12 (also via conda-forge) definitely. Older 8.6.x releases appear to yield better (yet not completely deterministic) results - also still seeking confirmation on this one.
There might be a chance that this happens exclusively to conda-forge builds but I have not had the chance to test this hypothesis yet.
Additional context: On some affected systems (not narrowed down enough yet), even simple tkinter text inputs and buttons are not being refreshed / redrawn at all - so it is not the only the Canvas that might be affected. I do not see a pattern there yet, so once I see, I will probably file another issue and reference it here.
The text was updated successfully, but these errors were encountered:
The problem occurs when a callback schedules itself to run again with after_idle(), presumably because it gets higher priority than updating the GUI. So every time the GUI is about to get updated, your callback function will run instead. I would recommend using something like .after(50, callback) instead of .after_idle(callback), because even if .after_idle() works, you will get 100% cpu usage as the event loop is never idle.
If you still believe this is a bug, we should report it to Tcl/Tk's bug tracker. That's what tkinter uses internally. You probably don't have experience with Tcl code, and I don't have a mac to reproduce the problem with, so we'd have to write the bug report together or let someone else do it.
From my, very, limited understanding of Tcl/Tk this is not a bug in Python or Tkinter, as @Akuli noted the code basically starves the Tcl/Tk event loop by making sure there's always work to do before updating the GUI.
Bug report
When geometries (e.g. an oval) on a tkinter Canvas widget are changed (e.g. moved), the Canvas is not redrawn on Mac OS. The following two code snippets reproduce the issue on Mac OS.
Expected behavior: One should see a circle moving from the top-left of the window/canvas to the right.
Actual behavior: In some cases, the circle is not even drawn in its initial position. In most cases, however, the circle is drawn in its initial position but does not "move" anywhere. While the Canvas does not change visually, the
updatefunction /_updatemethod in both examples does in fact get called repeatedly as one would expect.Variations: A call to the Canvas's
update_idletasksmethod (as commented out in my examples) may cause (or actually prohibit) the circle being drawn in its initial position. In theory (and on other operating systems), this call should not be necessary."Workaround": The exact same code works on various flavors of Linux and Windows and apparently on "older" versions of Mac OS (see below).
Example 1:
Example 2:
Your environment
Context: I first saw this issue with a bunch of university students and their Mac Books. I do not own a Mac Book so I had to gather this info (and confirmation of the above mentioned behavior) from various Mac Book owners.
There might be a chance that this happens exclusively to conda-forge builds but I have not had the chance to test this hypothesis yet.
Additional context: On some affected systems (not narrowed down enough yet), even simple tkinter text inputs and buttons are not being refreshed / redrawn at all - so it is not the only the Canvas that might be affected. I do not see a pattern there yet, so once I see, I will probably file another issue and reference it here.
The text was updated successfully, but these errors were encountered: