Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

does anyone know why my width is not defined, it seems that i have

from tkinter import *
import random
root=Tk()
root.geometry("400x400")

canvas = Canvas(root,width= width,height= height, bg='black')
canvas.pack(pady=20)
width,height=200,200
shape=canvas.create_circle(fill=yellow)

def pressed(event):
    index=random.randrange(0,5)
    x,y=0,0
    if event.char == "a":
        x,y =-10,0
    if event.char == "d":
        x,y =10,0w
    if event.char == "w":
        x,y =0,-10
    if event.char == "s":
        x,y =-0,10
root.bind("",pressed)

root.mainloop()

I think I have already defined width and height but I still get the error.This is why i am asking for help. Please answer!! :))

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are trying to use width and height before defining it. Just initialize width and height before using it, and you are good to go.

from tkinter import *
import random
root=Tk()
root.geometry("400x400")

width,height=200,200
canvas = Canvas(root,width= width,height= height, bg='black')
canvas.pack(pady=20)
shape=canvas.create_circle(fill=yellow)

def pressed(event):
    index=random.randrange(0,5)
    x,y=0,0
    if event.char == "a":
        x,y =-10,0
    if event.char == "d":
        x,y =10,0w
    if event.char == "w":
        x,y =0,-10
    if event.char == "s":
        x,y =-0,10
root.bind("",pressed)

root.mainloop()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading