|
This post has NOT been accepted by the mailing list yet.
In the short sample code below I have two print statements, each of which contains "itemcget()"
The first print statement works OK. It accesses the "fill" option and returns "red"
The second print statements generates an error-message. My intent is to print (or in general access) one of the coordinates of the oval (in this example, designated as x1).
In general my question is:
How to access the coordinates in a canvas. create_oval(x1,y1,x2,y2, options...) statement?
#==================== SAMPLE CODE ====================================
from Tkinter import *
class Appr:
def __init__(self,root):
self.c = Canvas(root, width=500, height=500)
self.c.pack(fill=BOTH, expand=YES)
x1=10
self.oval=self.c.create_oval(x1,10,20,20,fill="red",tags='red')
self.c.tag_bind('red', '<Button-1>', self.startDoIt)
def startDoIt(self,event):
widget = event.widget
self.startx, self.starty = widget.winfo_pointerxy()
print widget.itemcget(self.oval,"fill")
print widget.itemcget(self.oval, x1)
raw_input()
#=========== MAIN ====
root=Tk()
app=Ap(root)
root.mainloop()
|