Title: Tkinter bbox coordinates incorrectly drawn
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.10, Python 3.9, Python 3.8
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: epaine, rhoffmann, serhiy.storchaka
Priority: normal Keywords:

Created on 2021-01-21 20:56 by rhoffmann, last changed 2021-01-24 12:23 by serhiy.storchaka. This issue is now closed.

Messages (4)
msg385446 - (view) Author: Ron Hoffmann (rhoffmann) Date: 2021-01-21 20:56
position coordinates retrieved from any object on a canvas with
pos = canvas.bbox(object) are returned correctly

but when drawn on the canvas (x0,y0) are correct, but
(x1, y1) are not drawn in the proper positions. x1 has been divided by 2 somewhere and y1 as been multiplied by 2 somewhere.
in order for the bounding box to be drawn correctly
x1 and y1 need to be recalculated as follows

x1 = pos[0] + ( ( pos[2] - pos[0] ) * 2 )
y1 = pos[1] + ( ( pos[3] - pos[1] ) / 2 )
msg385504 - (view) Author: E. Paine (epaine) * Date: 2021-01-22 16:23
I cannot reproduce. Taking a rectangle as an example,
canvas.bbox(canvas.create_rectangle(5, 5, 100, 100, width=1))
returns `(4, 4, 101, 101)` (rather than `(5, 5, 100, 100)`) because of rounding while calculating the outline.

As a result, running
canvas.create_rectangle(canvas.bbox(canvas.create_rectangle(5, 5, 100, 100, width=1)), width=1, outline="yellow")
we see a black outline inside a yellow one (as to be expected).

Could we please have a minimal script to help diagnose the problem?
msg385505 - (view) Author: Ron Hoffmann (rhoffmann) Date: 2021-01-22 16:58
Thank you for your response. I have been fighting this issue in a large piece of code for quite some time.
So I wrote a small test script as you asked for and the problem will not reproduce. All behaviour of code is as expected.
I must therefore assume there is no bug in tkinter and the problem lies in my code or with my development environment.
Please consider the issue closed
msg385579 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-24 12:23
Even if there is something wrong with the returned values, Tkinter is just mostly a thin wrap around Tk. It does not change the returned value, it just converts it to appropriate Python type (a tuple of 4 integers (4, 4, 101, 101) instead of a string "4 4 101 101").
Date User Action Args
2021-01-24 12:23:52serhiy.storchakasetmessages: + msg385579
2021-01-23 18:08:13terry.reedysetstatus: open -> closed
stage: resolved
2021-01-22 16:58:01rhoffmannsetresolution: not a bug
messages: + msg385505
2021-01-22 16:23:08epainesetnosy: + serhiy.storchaka, epaine

messages: + msg385504
versions: + Python 3.9, Python 3.10
2021-01-21 20:56:49rhoffmanncreate