-1

I'm trying to make a basic pong game and starting by drawing a rectangle on the left side of the screen. When I run it i get the error of Cannot find reference 'pack' in 'None'. Thoughts?

import tkinter as tk

window = tk.Tk()
window.geometry('600x600')

canvas_width, canvas_height = 10,100
x1, y1 = canvas_width // 2, canvas_height // 2
canvas = tk.Canvas(window, width=canvas_width, height=canvas_height).place(x=1,y=0)
canvas.pack(side=tk.LEFT)

window.mainloop()
Blorpal
  • 19
  • 5

1 Answers1

2

Remove place from your canvas. The issue is that place() returns None, so your canvas object evaluates to None. You don't need place() if you're going to use pack().

Use one or the other (I prefer pack()) - and it's always a good idea to declare your widgets on one line, then add them to a geometry manager on another because, again, the geometry manager functions return None and you probably don't want that.

canvas = tk.Canvas(window, width=canvas_width, height=canvas_height)
canvas.pack(side=tk.LEFT)

OR

canvas = tk.Canvas(window, width=canvas_width, height=canvas_height)
canvas.place(x=1, y=0)
JRiggles
  • 4,847
  • 1
  • 12
  • 27