python 为什么tkinter画布矩形的参数“disabledwidth”不起作用?

cunj1qz1  于 2023-04-04  发布在  Python
关注(0)|答案(1)|浏览(128)

我希望画布中矩形的轮廓在矩形处于“禁用”状态时具有更大的宽度。因此,我使用参数“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()
6jjcrrmo

6jjcrrmo1#

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

编辑:这似乎是一个真正的错误。我已经提交了一个report

相关问题