Quantcast

itemcget question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

itemcget question

GKalman
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()
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: itemcget question

GKalman
This post has NOT been accepted by the mailing list yet.
Thanks to an earlier post by Michael Lange on  18 Dec 2011 at  17:30 the issue is resolved by the following statement:

        print "x1= ",(widget.coords(self.ovalt)[0])
Loading...