-1
from tkinter import *

root = Tk()
root.title("Sorting Algorithm Visualiser")
root.geometry("1500x780+0+0")
root.config(bg="#D7DBDD")

canvas

canvas = Canvas(root, width=1000, height=500, bg="#F8F9F9").pack()

rectangle on canvas what is error here

canvas.create_rectangle(50, 25, 150, 75, fill="red")

root.mainloop()

*Traceback (most recent call last): File "C:/Users/VINAYAK/PycharmProjects/try/try o1.py", line 10, in canvas.create_rectangle(50, 25, 150, 75, fill="red") AttributeError: 'NoneType' object has no attribute 'create_rectangle'

Process finished with exit code 1*

2
  • Canvas(root, width=1000, height=500, bg="#F8F9F9").pack() will return None,You should use canvas = Canvas(root, width=1000, height=500, bg="#F8F9F9") and canvas.pack() Commented Mar 14, 2020 at 12:58
  • its working..... Commented Mar 14, 2020 at 13:02

1 Answer 1

1

the issue is that you can't create and pack your canvas at the same time. this should work:

from tkinter import *

root = Tk()
root.title("Sorting Algorithm Visualiser")
root.geometry("1500x780+0+0")
root.config(bg="#D7DBDD")

canvas = Canvas(root, width=1000, height=500, bg="#F8F9F9")

canvas.create_rectangle(50, 25, 150, 75, fill="red")

canvas.pack()

root.mainloop()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.