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: canvas.bbox returns None on 'hidden' items while coords doesn't
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Vincent, epaine, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2021-03-10 13:51 by Vincent, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (8)
msg388432 - (view) Author: Vincent (Vincent) Date: 2021-03-10 13:51
canvas.bbox() should return a tuple containing values whether an item is hidden or not. canvax.coords() does return a tuple when an item is hidden.

Steps to reproduce:

```
  from tkinter import * 
  root = Tk()
  canvas = Canvas(root)
  id1 = canvas.create_line(10,5,20,5, tags='tunnel')
  id2 = canvas.create_line(10,8,20,8, tags='tunnel')
  canvas.bbox('tunnel')   # return a tupple
  canvas.itemconfig('tunnel', state='hidden')
  canvas.bbox('tunnel')   # return nothing not even None
```

I need bbox to return a tuple containing values. The consequences is that the code must make the items temporarily visible before it can invoke the bbox function. This turning on and off creates flashing items in my program.

Thanks in advance!
msg388439 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-03-10 15:55
What do you mean by "return nothing not even None"? Does it hang?
msg388450 - (view) Author: Vincent (Vincent) Date: 2021-03-10 18:46
No, not hang. It returns a NoneType.

See this example:

>>> x = canvas.bbox('tunnel')
>>> type(x)
<class 'NoneType'>
>>>
msg388502 - (view) Author: E. Paine (epaine) * Date: 2021-03-11 11:53
This can be easily reproduced in Wish (8.6.11):

% pack [canvas .c]
% .c create rectangle 10 10 90 90
1
% .c bbox 1
9 9 91 91
% .c create rectangle 20 20 80 80 -state hidden
2
% .c bbox 2
%

I doubt this is a bug because the docs (https://www.tcl.tk/man/tcl8.6/TkCmd/canvas.htm#M36) say:

> if the matching items have empty bounding boxes (i.e. they have nothing to display) then an empty string is returned
msg388504 - (view) Author: Vincent (Vincent) Date: 2021-03-11 13:28
Thank you for your comments. Yes, I would doubt that, too. You would expect to get a bounding box regardless what state the canvas item are in. The only way to fix this (and I'm open to suggestions), is to create a (custom) function that calculate every object belonging to a specific tag and add/subtract the coordinates - this is cumbersome.
msg388505 - (view) Author: Vincent (Vincent) Date: 2021-03-11 13:34
... calculate the coordinates using the canvas.coords function
msg388581 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-03-13 01:14
(You don't use coords('tunnel') above because it only reports on the 'first' tagged object.)

tkinter widget methods are generally thin wrappers around tk functions that translate between python objects and tk strings.

I believe that this should be closed as '3rd party' or 'not a bug'.
msg388597 - (view) Author: Vincent (Vincent) Date: 2021-03-13 08:07
HI Terry, yes, that's completely true. But what I meant is I have to invoke coords on every item belonging to a tag and then perform some calculations to get the boundary box of all the items belonging to the item. 

Let's close this issue and I will knock on the door of the developers of Tk.
History
Date User Action Args
2022-04-11 14:59:42adminsetgithub: 87628
2021-03-13 09:05:49Vincentsetstatus: open -> closed
resolution: not a bug
stage: resolved
2021-03-13 08:07:38Vincentsetmessages: + msg388597
2021-03-13 01:14:33terry.reedysetnosy: + terry.reedy
messages: + msg388581
2021-03-11 13:34:23Vincentsetmessages: + msg388505
2021-03-11 13:28:22Vincentsetmessages: + msg388504
2021-03-11 11:53:00epainesetnosy: + epaine
messages: + msg388502
2021-03-10 18:46:41Vincentsetmessages: + msg388450
2021-03-10 15:55:54serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg388439
2021-03-10 13:52:20Vincentsettype: behavior
2021-03-10 13:51:23Vincentcreate