How to reconfigure tkinter canvas items?

后端 未结 2 800
广开言路
广开言路 2020-12-19 21:57

I don\'t know if this question has duplicates , but i haven\'t found one yet.

when using python you can create GUI fastly , but sometimes you cannot find a method to

相关标签:
2条回答
  • 2020-12-19 22:28

    You can use Canvas.itemconfig:

    item = K.create_rectangle(x1,y1,x2,y2,options...)
    K.itemconfig(item,options)
    

    To move the item, you can use Canvas.move


    import Tkinter as tk
    
    root = tk.Tk()
    canvas = tk.Canvas(root)
    canvas.pack()
    item = canvas.create_rectangle(50, 25, 150, 75, fill="blue")
    
    def callback():
        canvas.itemconfig(item,fill='red')
    
    button = tk.Button(root,text='Push me!',command=callback)
    button.pack()
    
    root.mainloop()
    
    0 讨论(0)
  • 2020-12-19 22:30

    I searched around and found the perfect Tkinter method for resizing. canvas.coords() does the trick. just feed it your new coordinates and it's "good to go". Python 3.4
    PS. don't forget the first param is the id.

    0 讨论(0)
提交回复
热议问题