from tkinter import * root = Tk() canvas = Canvas(root) canvas.pack() # create a rectangle rect = canvas.create_rectangle(50, 50, 100, 100) # get the current position of the rectangle pos = canvas.coords(rect) print(pos) root.mainloop()
from tkinter import * root = Tk() canvas = Canvas(root) canvas.pack() # create a rectangle rect = canvas.create_rectangle(50, 50, 100, 100) # move the rectangle to a new position canvas.coords(rect, 100, 100, 150, 150) root.mainloop()In this example, we create a rectangle using the Canvas.create_rectangle method, and then use the Canvas.coords method to set the position of the rectangle to `(100, 100, 150, 150)`. Overall, Python Tkinter Canvas provides a simple and powerful way to create GUIs with customizable graphics, and the Canvas.coords method is just one of many tools available in this library.