Closed jojo-monk closed 8 months ago
I edited the description to match the buttons displayed. [Matrice] shows grid with spinboxes, [create grid] shows grid alone, so if already present, all should disappear. They do on Windows, so I added OS-macos tag. I have no idea what "mouse click is shifted from the blackened boxes." means. The only black box I see is a quick black flash of upper left box.
I cannot reproduce with Python 3.12 from our installer.
The hit testing for the grid cells is a bit off when first creating a matrix and then the grid, that's because the entire grid is shifted a little when the spin boxes are shown and that position is not reset when the spin boxes are hidden again. That's not an issue we can fix on our side (if this is a bug at all), but is behaviour from Tk.
BTW. I get the following exception when clicking on one of the spin boxes I get the following traceback ("Matrice", "create grid", "Matrice"):
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tkinter/__init__.py", line 1962, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "/Users/ronald/Projects/py2app/repro.py", line 101, in click_1case
couleur_actuelle = grille_frame.itemcget(case, "fill")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/tkinter/__init__.py", line 2964, in itemcget
return self.tk.call(
^^^^^^^^^^^^^
_tkinter.TclError: unknown option "-fill"
The exception does only happen if I click on "Matrice" after clicking on "create grid".
Yes I have the same exception, to illustrate my point, here is a screenshot obtained after clicking on [Matrice], then [create grid], I added red dots on the boxes where I clicked to show the offset between the click and the affected box:
I don't see the spinner on my system, but do see similar clicking behaviour although I have to click closer to the edge of a cell to get a wrong hit.
Some more testing:
click_1case
function isn't called on changes either. The exception appear to be a bug in your code, the click handler tries to change the fill of something that isn't a grid cell. That said, I'm not a Tk expert.grille_frame.bind("<Button-1>", click_1case)
With that change clicking works reliably regardless of how many times I click on Matrice and "create grid".
The mouse offset bug is solved with:
x, y = grille_frame.canvasx(event.x), grille_frame.canvasy(event.y)
print("clic souris", event.x, event.y, x, y)
case = grille_frame.find_closest(x, y) # used the real coordinates
In the click_1case function.
The offset issue is also solved by binding the click event to the frame (see my previous message). Might be related to window-relative vs. widget-relative coordinates, but I'm not enough of an Tk expert to know this for sure.
All in all I don't think this is a bug in CPython.
Bug report
Bug description:
Hello,
In this code, if you click on matrix, then create grid, there is a spinbox that remains displayed. and the mouse click is shifted from the blackened boxes.
CPython versions tested on:
3.11
Operating systems tested on:
macOS