I’ve been searching forums for over an hr and can’t find anything. I’m following a tutorial for a snake game and I keep getting the bad geometry error. No spaces between numbers, im using x, not *, it’s lowercase… it’s driving me crazy!
from tkinter import *
import random
GAME_WIDTH = 700
GAME_HEIGHT = 700
SPEED = 50
SPACE_SIZE = 50
BODY_PARTS = 3
SNAKE_COLOR = "#00FF00"
FOOD_COLOR = "#FF0000"
BACKGROUND_COLOR = "#000000"
window = Tk()
window.title("Snake game")
window.resizable(False, False)
score = 0
direction = 'down'
label = Label(window, text="Score:{}".format(score), font=('consolas', 40))
label.pack
canvas = Canvas(window, bg=BACKGROUND_COLOR, height=GAME_HEIGHT, width=GAME_WIDTH)
canvas.pack
window.update()
window_width = window.winfo_width()
window_height = window.winfo_height()
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
x = int(screen_width/2) - (window_width/2)
y = int(screen_height/2) - (window_height/2)
window.geometry(f"{window_width}x{window_height}+{x}+{y}")
window.mainloop()
I’m getting this error message and I can’t find what I’m doing wrong
Traceback (most recent call last):
File “/Users/macbook/PycharmProjects/PracticeMac/main.py”, line 56, in
window.geometry(f"{window_width}x{window_height}+{x}+{y}")
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tkinter/init.py”, line 2100, in wm_geometry
return self.tk.call(‘wm’, ‘geometry’, self._w, newGeometry)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_tkinter.TclError: bad geometry specifier “200x200+740.0+425.0”