Mar-30-2026, 07:26 PM
I have successfully created a widget of type Canvas, but when I want to use its attributes I get a NoneType error
The canvas is created, but the name is not recognized in the next statement:
AttributeError: 'NoneType' object has no attribute 'create_line'
I must be doing something wrong... Thanks in advance for any help
root = tk.Tk() frame = tk.Frame(root) frame.grid() panel = tk.Canvas(frame, width=panel_width, height=panel_height, bg="silver").grid(row=0, column=0) btn = tk.Button(frame, text="Quit", command=root.destroy).grid(row=1, column=0)
The canvas is created, but the name is not recognized in the next statement:
panel.create_line(0, 20, panel_width, 20, fill="red", width=2)I get an error:
AttributeError: 'NoneType' object has no attribute 'create_line'
I must be doing something wrong... Thanks in advance for any help
