Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

canvas.bbox returns None on 'hidden' items while coords doesn't #87628

Closed
yutanicorp mannequin opened this issue Mar 10, 2021 · 8 comments
Closed

canvas.bbox returns None on 'hidden' items while coords doesn't #87628

yutanicorp mannequin opened this issue Mar 10, 2021 · 8 comments
Labels
3.7 (EOL) end of life topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@yutanicorp
Copy link
Mannequin

yutanicorp mannequin commented Mar 10, 2021

BPO 43462
Nosy @terryjreedy, @serhiy-storchaka, @E-Paine, @yutanicorp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2021-03-13.09:05:49.375>
created_at = <Date 2021-03-10.13:51:23.888>
labels = ['3.7', 'invalid', 'type-bug', 'expert-tkinter']
title = "canvas.bbox returns None on 'hidden' items while coords doesn't"
updated_at = <Date 2021-03-13.09:05:49.375>
user = 'https://github.com/yutanicorp'

bugs.python.org fields:

activity = <Date 2021-03-13.09:05:49.375>
actor = 'Vincent'
assignee = 'none'
closed = True
closed_date = <Date 2021-03-13.09:05:49.375>
closer = 'Vincent'
components = ['Tkinter']
creation = <Date 2021-03-10.13:51:23.888>
creator = 'Vincent'
dependencies = []
files = []
hgrepos = []
issue_num = 43462
keywords = []
message_count = 8.0
messages = ['388432', '388439', '388450', '388502', '388504', '388505', '388581', '388597']
nosy_count = 4.0
nosy_names = ['terry.reedy', 'serhiy.storchaka', 'epaine', 'Vincent']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue43462'
versions = ['Python 3.7']

@yutanicorp
Copy link
Mannequin Author

yutanicorp mannequin commented Mar 10, 2021

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!

@yutanicorp yutanicorp mannequin added 3.7 (EOL) end of life topic-tkinter type-bug An unexpected behavior, bug, or error labels Mar 10, 2021
@serhiy-storchaka
Copy link
Member

What do you mean by "return nothing not even None"? Does it hang?

@yutanicorp
Copy link
Mannequin Author

yutanicorp mannequin commented Mar 10, 2021

No, not hang. It returns a NoneType.

See this example:

>>> x = canvas.bbox('tunnel')
>>> type(x)
<class 'NoneType'>
>>>

@E-Paine
Copy link
Mannequin

E-Paine mannequin commented Mar 11, 2021

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

@yutanicorp
Copy link
Mannequin Author

yutanicorp mannequin commented Mar 11, 2021

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.

@yutanicorp
Copy link
Mannequin Author

yutanicorp mannequin commented Mar 11, 2021

... calculate the coordinates using the canvas.coords function

@terryjreedy
Copy link
Member

(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'.

@yutanicorp
Copy link
Mannequin Author

yutanicorp mannequin commented Mar 13, 2021

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.

@yutanicorp yutanicorp mannequin closed this as completed Mar 13, 2021
@yutanicorp yutanicorp mannequin added the invalid label Mar 13, 2021
@yutanicorp yutanicorp mannequin closed this as completed Mar 13, 2021
@yutanicorp yutanicorp mannequin added the invalid label Mar 13, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life topic-tkinter type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants