Skip to content

disabledwidth in canvas.create_rectangle is ignored, needs to be set with canvas.itemconfig #103216

@brockbrownwork

Description

@brockbrownwork

Bug 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:

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()

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. Here's where it says that this option should exist: https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/create_rectangle.html

This is the workaround code:

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()

Your environment

  • CPython versions tested on:
    3.10.4
  • Operating system and architecture:
    Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions