Well there are ways of working around the inexact results from bbox, for instance, take the average of the x and y coords and that will give you the center of the item. You can work out a way with the anchor for the item, to get the exact position.

You haven't shown any code and you are throwing around terms like "pack with grid" for canvas items. I'm not sure you understand...... the canvas widget itself can be packed or gridded, but items on the canvas cannot.....they are placed somewhere on the canvas. Unless you are talking about a grid item (read perldoc Tk::Canvas and search for createGrid). So you can't use packForget,etc, except on the canvas widget itself.

As far as finding positions of items, each item type will have it's own quirks. Some items, you can get the "coords" or "x" ,"y". But you need to know how many points are there, like in polygons.

my @coords = $canvas->coords($id); my ( $x0, $y0, $x1, $y1 ) = $canvas->coords($id);
Sometimes you need to use the bbox. The bbox is useful for finding a bounding box of a group of similarly tagged items. Bbox is also useful for text (to account for font size).

It is not too hard to setup a hash, and store your positions exactly if that is easier for you. In Tk::Zinc( a suped-up canvas), positions can be kept with tget and tset (transformation matrix), see Newtons-Cradle-Tk-Zinc. In that case, it was difficult to get the balls to return to their starting rest position without a jitter effect.


I'm not really a human, but I play one on earth CandyGram for Mongo

In reply to Re^5: Fogetting Tk Canvas widgets by zentara
in thread Fogetting Tk Canvas widgets by merrymonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.