Tkinter.Canvas.create_line.coords
Arnd Baecker
arnd.baecker at web.de
Sun Jun 1 03:53:20 EDT 2003
Hi,
I have a question concerning modifying a line created
within a Canvas:
It boils down to that (for `plot` being a Canvas)
self.plot.coords(self.line,10,0,10,10,80,100,100,200)
works, whereas
liste=[10,0,10,10,80,100,100,200]
self.plot.coords(self.line,liste)
raises the error:
self.tk.splitlist(
TclError: bad screen distance "[10,"
((Maybe the example below more clearly demonstrates what I mean here.))
Actually, help(Tkinter.Canvas.coords) gives
coords(self, *args) unbound Tkinter.Canvas method
Return a list of coordinates for the item given in ARGS.
which seems to me a bit different from the description on page 14
given in the "Tkinter reference: A GUI for Python"
(John Shipman, New Mexico Tech Computer Center), which says
that you can do the above as well, i.e. passing a new set of
coordinates. Alternative reference for this:
http://www.pythonware.com/library/tkinter/introduction/canvas-line.htm
Is there a different method I should use to change the coordinates?
((More background: For a <B1-Motion> event for the above line
I want to change its points according to the mouse position,
so deleting and recreating the object does not work
for a continuous change.
Also I need around 100-300 points in my application.))
Any help is appreciated!
Arnd
##### sample programm:
"""
Click on the "Action" button to reveal the problem
"""
from Tkinter import *
class Test(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
Pack.config(self)
self.createWidgets()
def action_(self):
print "action"
self.plot.coords(self.line,10,0,10,10,80,100,100,200)
def action(self):
print "action2, This one fails:"
liste=[10,0,10,10,80,100,100,200]
self.plot.coords(self.line,liste)
def createWidgets(self):
self.QUIT = Button(self, text='QUIT', foreground='red',
command=self.quit)
self.Action = Button(self, text='Action', foreground='red',
command=self.action)
self.plot=Canvas(self, width="5i", height="5i")
liste=[0,0,10,10,80,150,200,200]
self.line=self.plot.create_line(liste)
self.plot.pack(side=TOP)
self.QUIT.pack(side=LEFT, fill=BOTH)
self.Action.pack(side=LEFT, fill=BOTH)
test = Test()
test.mainloop()
More information about the Python-list
mailing list