-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*

1 Answers1

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()
rémi couturier
  • 425
  • 3
  • 11