Changing the colour on click of a tkinter rectangle on click in python

后端 未结 1 1826
有刺的猬
有刺的猬 2021-01-12 02:46

So I have this code which draws a simple rectangle:

from tkinter import *

root = Tk()
canvas = Canvas(root, width = 500, height = 500)
canvas.pack()

canvas         


        
相关标签:
1条回答
  • 2021-01-12 03:15

    Name it and then refer to it through itemconfig, like this:

    myrectangle = canvas.create_rectangle(100, 100, 400, 400, fill='black')
    canvas.itemconfig(myrectangle, fill='red')
    
    0 讨论(0)
提交回复
热议问题