我希望在画布上的矩形的轮廓获得更大的宽度,当矩形处于"禁用"状态时.因此,我使用参数"DisabledWidth=4".但当矩形处于"禁用"状态时,轮廓的宽度仍为1而不是4.
这是我的代码,它显示了问题:当我将鼠标移到矩形上时,矩形的状态更改为"活动",一切都按预期工作,特别是轮廓宽度更改为4.但是,当我通过单击按钮将状态更改为"禁用"时,轮廓保持在宽度1.我做错了什么?
import tkinter as tk
def disabled():
canvas.itemconfig(rect, state="disabled")
def normal():
canvas.itemconfig(rect, state="normal")
root = tk.Tk()
canvas = tk.Canvas(root, height=250, width=250)
button1 = tk.Button(root, text="change rectangle to state disabled", command=disabled)
button2 = tk.Button(root, text="change rectangle to state normal" , command=normal )
rect = canvas.create_rectangle(40, 40, 180, 180,
fill = "red",
activefill = "green2",
activeoutline = "green3",
activewidth = 4,
disabledfill = "grey",
disabledoutline= "grey2",
disabledwidth = 4
)
canvas.grid()
button1.grid()
button2.grid()
root.mainloop()