Home > Software design >  nothing has come on my window and i'm not sure why
nothing has come on my window and i'm not sure why

Time:08-08

from tkinter import *

root=Tk()
root.geometry("400x400")

width,height= 400, 400

canvas = Canvas (root, width=width,height= height, bg="black")

shape=canvas.create_oval (width/2,height/2,width/2 10,height/2 10, fill="yellow")


def Left(event):
    x= -10
    y=-0
    canvas.move(shape,x,y)

def Right(event):
    x=10
    y=0
    canvas.move(shape,x,y)

def Up(event):
    x=0
    y=-10
    canvas.move(shape,x,y)

def Down(event):
    x=0
    y=10
    canvas.move(shape,x,y)

root.bind("<Left>",Left)
root.bind("<Right>",Right)
root.bind("<Up>",Up)
root.bind("<Down>",Down)
root.mainloop()

I am not getting any errors but a blank window. I will put a ss of the window for evidence. I haven't got enough reputation for an embedded image but just paste the link in your browser.

CodePudding user response:

I was suspicious when running your code that the main window was white rather than the black that you specify for the canvas.

I looked around and just added:

canvas.pack(expand=YES,fill=BOTH)

and the canvas appears with a yellow circle on it.

  • Related