我希望画布中矩形的轮廓在矩形处于“禁用”状态时具有更大的宽度。因此,我使用参数“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()
1条答案
按热度按时间6jjcrrmo1#
以
canvas.itemconfig
为单位指定宽度编辑:这似乎是一个真正的错误。我已经提交了一个report。