[tkinter] two questions regarding Canvas
Greg McFarlane
gregm at iname.com
Thu Jun 3 10:59:22 EDT 1999
This is small attempt at adding editing bindings to canvas text items.
This *must* have been done before, but a search of comp.lang.tcl did
not come up with anything, except a mention of pg_access in postgresql
which I could not find. Does anyone know of it?
======================================================================
import Tkinter
def click(event):
canvas.delete('rect')
region = canvas.bbox('current')
if region is None:
canvas.focus('')
else:
canvas.create_rectangle(region, outline = 'blue', tags = 'rect')
canvas.focus('current')
canvas.icursor('current', '@%d,%d' % (event.x, event.y))
def double(event):
canvas.select_from('current', 0)
canvas.select_to('current', 'end')
root = Tkinter.Tk()
canvas = Tkinter.Canvas(root)
canvas.pack()
canvas.bind('<Button-1>', click)
item1 = canvas.create_text(100, 100, text = 'Hello\nthere', tags = 'text')
item2 = canvas.create_text(200, 100, text = 'Good evening', tags = 'text')
canvas.focus_set()
# Need lots more bindings: button motion (for changing the selection),
# keys (for adding and deleting text), etc (same as text widget).
canvas.tag_bind('text', '<Double-1>', double)
root.mainloop()
======================================================================
On 2 Jun, Joseph Robertson wrote:
> Sure does, heres some relevant clips. Sorry I couldn't send the whole
> thing but its too big.
> I have a class that creates the canvas, then I set the binding:
>
> def __init__(self)
> ...
> self.canvas.bind('<Button-1>', self.CellClick)
> ...
>
> Heres the working method:
> def CellClick(self, event):
> self.canvas.delete('rect')
> cellbbox = self.canvas.bbox('current')
> self.canvas.create_rectangle(cellbbox, outline='blue',
> tags='rect')
>
>
> Now I don't have it editable yet, I am using this,
> item = self.canvas.create_text(xpos, ypos, text=field, font=self.f)
>
> in a loop to put data onto the canvas.
>
> I'm sure that creating a hidden Entry and the moving it and making it
> visible would work fine, or don't move it and make a 'status line' type
> of data editing, like Lotus did.
>
> Good Luck,
> Joe
>
>
>
> mlauer at amalia-atm.rz.uni-frankfurt.de wrote:
>
> > Howdy, though I'm gaining knowledge through
> > browsing through all the available documentation
> > (that is, the tkinter life-preserver, tkinter.py
> > and the tk/tcl documentation) some things
> > remain misterious...
> >
> > For instance:
> >
> > a) Does the tk Canvas support "inplace" editing of
> > text items or what are the functions Canvas.icursor
> > and Canvas.focus for ? If so, how ? For instance,
> > binding the <Any-Enter> to a text item function,
> > which sets icursor and focus doesn't work for me
> > (yes, the canvas has the current focus)
> >
> > b) Does the Canvas support a visible selection
> > of items (such as a boundaring rectangle or so)
> > on its own or have I to do this via binding <Any-Enter>
> > and <Any-Leave> ?
> >
> > Have a nice day!
> >
> > --
> > Regards & Gruesse from Mickey @ http://www.Vanille.de
> > ---------------------------------------------------------
> > How could anyone know me - when I don't even know myself ?
>
>
>
>
>
--
Greg McFarlane: INMS Telstra Australia (gregm at iname.com)
Today's forecast: Sunny, with occasional cloudy periods and a chance
of rain in some areas.
More information about the Python-list
mailing list