how to get id of a line from his coordonée in tkinter python?

Discussion in 'Python' started by olsr.kamal@gmail.com, Mar 9, 2013.

  1. Guest

    how to get id of a line from his coordonée in tkinter python?
     
    , Mar 9, 2013
    #1
    1. Advertising

  2. Rick Johnson Guest

    On Saturday, March 9, 2013 4:46:40 PM UTC-6, wrote:
    > how to get id of a line from his coordonée in tkinter python?


    Each time you create a "canvas item", be it a rectangle, line, circle, or whatever..., the id of that object is returned as an integer. All you have to do is save the id into a variable.

    rectID = canvas.create_rectangle(...)

    Now you can pass that unique id into many of the methods that exist for "canvas items".

    canvas.delete(rectID)
    canvas.coords(rectID)
    canvas.bbox(rectID)

    *Sarcastic Sam quipped*: """Rick, not everybody can be as smart as you! What if we forgot to save the return value into a variable? Besides, you cannot expect us to create a variable to hold *every single* id of *every single* canvas object; that would be ridiculous!"""

    Indeed it would Sam. Besides, integer tags are not easy to remember, and they are created by the canvas object (which is out of your control).

    But before you throw the computer out the window, be aware that the canvas allows you to tag each "canvas item" by passing one or more strings, using the "tags=..." argument, into the "canvas.create_X(args)" methods.

    py> canvas.create_rectangle(0,0,10,10, fill='red', tags='red_rect')
    py> canvas.coords('red_rect')
    (0,0,10,10)

    PS: Hopefully you solved that other issue.
     
    Rick Johnson, Mar 9, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lukasz
    Replies:
    0
    Views:
    455
    Lukasz
    Apr 6, 2004
  2. gb345
    Replies:
    9
    Views:
    503
    Ulrich Eckhardt
    Oct 21, 2010
  3. gb345
    Replies:
    32
    Views:
    733
    Lawrence D'Oliveiro
    Oct 30, 2010
  4. Replies:
    1
    Views:
    107
    Mark Lawrence
    Mar 13, 2013
  5. Replies:
    0
    Views:
    114
Loading...

Share This Page