Placing the text by its upper-left corner

The anchor option allow us to control where to place the item relative to the position passed as its first argument to canvas.create_text(). By default, this option value is tk.CENTER, which means that the text widget is centered on these coordinates.

If you want to place the text on the upper-left corner of the canvas, you can do so by passing the (0, 0) position and setting the anchor option to tk.NW, aligning the origin to the north-west of the rectangular area the text is placed within:

        # ...
options = { "font": "courier", "fill": "blue",
"activefill": "red", "anchor": tk.NW }
self.text_id = self.canvas.create_text((0, 0), **options)

The preceding code snippet will give us the following result:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset