title: how to measure the width of a tkinter canvas text
body: <p>I was wondering how to measure the width of a text in tkinter canvas. I have a text displayed somewhere:</p>
  <pre><code>myCanvas.create_text(400,410, text=&quot;This is my text&quot;, tags=&quot;my_tag&quot;)
  </code></pre>
  <p>and at some point there is a shape (polygon line) that may overlap when the text gets longer (text will be changed with <code>.itemconfigure()</code>). In this case I wanted to break the text in lines, which works well with the <code>width</code> option.</p>
  <p>To figure out if objects overlap there are a couple of possible methods: <code>find_overlapping()</code> or <code>find_enclosed()</code>, however, they do require 4 coordinates and <code>myCanvas.coords(&quot;my_tag&quot;)</code> only returns 2 coordinates. How could I figure out the other <code>x2</code>, <code>y2</code>?</p>
  <p>An alternative was to use <code>find_closest()</code>, however, there are a bunch of shapes closer than the overlapping one, so that is not accurate.</p>
  <p>Another alternative was that I could figure out the intersecting coordinate and then just take the distance to the x coordinate of the text and double that as a width (since text gets drawn from the center), for example:</p>
  <p>intersection point at <code>(350,405)</code> =&gt; <code>width = 2 * (400-350)</code></p>
  <p>However, since the shape is a line (part of a polygon) that goes diagonal, I'm not sure how get the intersection point other than having a loop that creates a line that slowly increases till it overlaps with an object, for example:</p>
  <pre><code>text_center = (400,410)
  start_x = text_center[0]
  start_y = text_center[1]
  extender = 1
  while(myCanvas.find_overlapping(start_x, start_y, start_x+entender, start_y == ())
       myCanvas.delete(&quot;mytestline&quot;)
       extender += 1
       myCanvas.create_line(start_x, start_y, start_x+extender, start_y, tags=&quot;mytestline&quot;)
  overlapping_point = (start_x+extender, start_y)
  </code></pre>
  <p>Is there an easier way?</p>