my title might be a little confusing but basically I have a function that makes a rectangle in tkinter python.
w = Canvas()
def rectangle(x0,y0,x1,y1,fill):
w.create_rectangle(x0,y0,x1,y1,fill=fill)
return;
so I have this. It works if I try it on the canvas. Now I want to move it.
test = rectangle(1,1,20,20,"blue")
this also works but if I do
print(w.coords(test))
I get an error message saying that there is no value for it, and if I print just the plain variable out it says its
none
Thanks in advance
Your function will return None
by default. I don't understand what you want to do by using return;
after the function definition, but I think this is what you want:
w = Canvas()
def rectangle(x0,y0,x1,y1,fill):
return w.create_rectangle(x0,y0,x1,y1,fill=fill)
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.