Placing entry widgets on a canvas in Tkinter

Fredrik Lundh fredrik at pythonware.com
Mon Jun 30 08:49:48 EDT 2003


Mickel Grönroos wrote:

> I'm trying to put an Tkinter.Entry of fixed size onto a specific location
> on a canvas using the place manager. The idea is that one can double-click
> a rectangle object on a canvas to get an entry field of the same size
> as the rectangle placed exactly over the rectangle thus creating
> the effect that the rectangle has entered "input mode". When clicking
> return in the entry field, the value is fed back to a text object within
> the rectangle object on the canvas.

> Well, this works fine and well until the canvas is scrolled of one reason
> or another. When that happens, the entry naturally does not follow the
> canvas. Is there a way to lock a widget which is "placed" onto a canvas
> to the canvas so that it follows the canvas as it scrolls or is rescaled?

try this:

    canvas.create_window(x, y, window=widget, anchor=NW)

(also make sure to always use canvas.canvasx(screenx) and
canvas.canvasy(screeny) to convert between screen coordinates
and canvas coordinates in your event handlers)

an alternative solution is to implement text editing for text items;
see

    http://effbot.org/guides/editing-canvas-text-items.htm

for a discussion, and some code.

</F>








More information about the Python-list mailing list