This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: turtle.onrelease() event doesn't get triggered sometimes
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.11, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: epaine, techn010je11y, terry.reedy
Priority: normal Keywords:

Created on 2021-08-28 13:15 by techn010je11y, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
pain2exp.py techn010je11y, 2021-08-28 13:15 Paint wannabe that has bugs
Messages (5)
msg400470 - (view) Author: Techn010 Je11y (techn010je11y) Date: 2021-08-28 13:15
(pls read with reference to attached code)

I made a Paint-ish program with Turtle. As there isn't ondrag or onrelease for Screen, I created a turtle named bg so I could use ondrag and onrelease (see file attached ig) and eliminate the need for double-clicking(previously I used Screen.onclick to pen.up(), move it to cursor, and pen.down() then use turtle.drag() to draw). However, I noticed that it doesn't work(turtle doesn't penup when mouse is released sometimes) and added the print("...", i(or j)) bits(pls see code). On at least 1 instance 'start' was printed without a corresponding release. I'm a beginner so I apologise if it's just a bug in my code. I did not install anything related to python after I installed 3.9.6(64-bit btw). I do not have any other versions. I did not alter any part of what's installed.

System info:
Windows 10 Pro Education
Version 10.0.19043(or 21H1), Build 19043.1165
Windows Feature Experience Pack 120.2212.3530.0
Lenovo L13 Gen 2, x64 based PC
11th Gen Intel Core i5-1135G7 @ 2.4GHz, 4 Cores, 8 logical processors
8GB ram

Attached is my code(I'm sorry if it hurts your eyes)
msg400478 - (view) Author: E. Paine (epaine) * Date: 2021-08-28 15:50
The issue is that the "release" function appears to be called before the "drag" function for the last coordinate. The fix is probably only lowering the pen when the mouse button is first clicked, as this is guaranteed to be called before "release". I ended up with something like the following (after removing the pen lower logic from the "release" function):

def down(a, b):
    print("down")
    p.goto(a, b)
    p.down()
bg.onclick(down)
msg400500 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-08-28 20:16
(turtle module has no relation to IDLE other than also using tkinter.  The fact that turtledemo can be run from IDLE is incidental.)

3.10.0rc installed on Win 10.  I first clicked randomly and never saw a missing 'release'.  I noticed that the turtle occasionally jumped to where I clicked, with 'start n' being printed.  I realized that I must have moved the mouse at least a pixel between click and release, triggering a move event.

I then did multiple click-drag-releases.  I am not sure if I ever saw a missing 'release', but sometimes saw an extra 'start' as I released, especially when releasing while moving the mouse.  EP's comment explains this.  A subsequent click and drag prints no 'start' (which really means 'pen down') because the pen was already down.

I see two possible issues:

1. https://docs.python.org/3.9/library/turtle.html#using-events talks about events 'on this turtle'.  Should that mean clicks anywhere on the screen or just literally 'on' the turtle image.  If there were multiple turtles, should 'anywhere on the screen' be 'on' all' of them?  The meaning of 'on' is turtle-specific, so this might be a turtle bug, depending on the intention.

2. The OS sends its graphics screen mouse move events corresponding to the physical mouse being moved.  There are available to tk.  ondrag is supposed to only notice those after button press (and by implication before button release).  In other words, while the button is down.  There should be not be drag events after the release event.  This might be a turtle bug, but could be in tk or even the OS mouse driver
msg400699 - (view) Author: Techn010 Je11y (techn010je11y) Date: 2021-08-31 08:15
I tried EP's fix. Sometimes it doesn't pendown when I drag, and only does when I stop moving my mouse for a moment(or just release).
msg402078 - (view) Author: E. Paine (epaine) * Date: 2021-09-17 19:17
> Sometimes it doesn't pendown when I drag

Sorry, I can't think why this would be. Maybe ask on Stack Overflow? For now, though, I doubt it's a bug with turtle so IMO this issue should be closed.
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89199
2021-09-17 19:17:37epainesetmessages: + msg402078
2021-08-31 08:15:44techn010je11ysetmessages: + msg400699
2021-08-28 20:16:01terry.reedysetassignee: terry.reedy ->
messages: + msg400500
components: + Library (Lib), - IDLE, Tkinter
versions: + Python 3.11
2021-08-28 15:50:46epainesetnosy: + epaine
messages: + msg400478
2021-08-28 13:15:14techn010je11ycreate