Why does the parameter "disabledwidth" of a tkinter canvas rectangle not work?
Question:
I want the outline of a rectangle in a canvas to get a bigger width, when the rectangle is in state "disabled". Therefore I use the parameter "disabledwidth=4". But when the rectangle is in state "disabled", the outline has still a width of 1 instead of 4.
This is my code, which shows the problem: When I move the mouse over the rectangle, the state of the rectangle changes to "active", everything works as expected, especially the outlinewidth changes to 4. But when I change the state to "disabled" by clicking on the button the outline stays at width 1. What am I doing wrong?
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()
Answers:
Specify the width in canvas.itemconfig
import tkinter as tk
def disabled():
canvas.itemconfig(rect, state="disabled", width=4)
def normal():
canvas.itemconfig(rect, state="normal", width=1)
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",
width = 1
)
canvas.grid()
button1.grid()
button2.grid()
root.mainloop()
Edit: This appears to be a genuine bug. I have filed a report.
I want the outline of a rectangle in a canvas to get a bigger width, when the rectangle is in state "disabled". Therefore I use the parameter "disabledwidth=4". But when the rectangle is in state "disabled", the outline has still a width of 1 instead of 4.
This is my code, which shows the problem: When I move the mouse over the rectangle, the state of the rectangle changes to "active", everything works as expected, especially the outlinewidth changes to 4. But when I change the state to "disabled" by clicking on the button the outline stays at width 1. What am I doing wrong?
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()
Specify the width in canvas.itemconfig
import tkinter as tk
def disabled():
canvas.itemconfig(rect, state="disabled", width=4)
def normal():
canvas.itemconfig(rect, state="normal", width=1)
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",
width = 1
)
canvas.grid()
button1.grid()
button2.grid()
root.mainloop()
Edit: This appears to be a genuine bug. I have filed a report.