简体   繁体   中英

Change coords of line in python tkinter canvas

I've drawn a line in tkinter.Canvas and now I want to move one end. Is this possible, eg with itemconfig ?

import tkinter

tk = tkinter.Tk()
canvas = tkinter.Canvas(tk)
canvas.pack()
line = canvas.create_line(0, 0, 100, 100)
tk.mainloop()

Now I want to change the end of the line to 75, 25 . Is there a better way as to delete the line and create a new one?

Once you've created some item on canvas you can use the following methods to edit the item:

  • coords( )
  • itemconfig( )
  • move( )

For example:

from tkinter import *

root = Tk()
w = Canvas(root, width=200, height=200)
w.pack()
var = w.create_line(0, 0, 100, 100)
w.coords(var, 0, 0, 75, 25)
root.mainloop()

For learning more about Canvas , you may refer:

canvas.coords(line, 0, 0, 75, 25)是解决方案

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM