tkinter widget doesnt move

59 views Asked by At

i have a widget which if i stand at coords lets say 100 and he is at coords 200 he is supposed to move to 100 he is supposed to follow me i did print his coords like u can see in the code and its the right coords but the widget photo itself doesnt move i cant see it

i have a move function and i did that while i move it calls the hzom and zombie functions and i call the at the start of the code too

food.label is the player

def zombie():

    if list3[0]>=Food.label.winfo_x():
        while list3[0]>=Food.label.winfo_x():

            print("fdkfj")
            list3[0]=list3[0]-0.5
            parent1.move(w,-0.05,0)
            print(list3[0])
            print(list3[1])
    if list3[0]<=Food.label.winfo_x():
        while list3[0]<=Food.label.winfo_x():
            print(list3[0])
            print(list3[1])
            print("fdkfj")
            list3[0]=list3[0]+0.5
            parent1.move(w,0.05,0)
def hzom():
    global parent1
    parent1=Canvas(wind,width = 50,height = 50)
    parent1.pack()
    global oval12
    global w
    w =parent1.create_oval(0,0,50,50,fill = "blue",tags="oval12")
    global list3
    list3 = [1300, 640]
    parent1.place(x=list3[0],y=list3[1])
    print("d")

hzom()
zombie()

1

There are 1 answers

0
coder34321553667 On

what worked for me is moving the place of only the canvas not the ball

        global parent1
        parent1 = Canvas(wind, width=50, height=50)
        global oval12
        global w
        w = parent1.create_oval(0, 0, 50, 50, fill="blue", tags=("oval12",))
        global list3
        list3 = [1300, 640]
        parent1.place(x=list3[0], y=list3[1])
        print("d")

    def zombie():
        if list3[0] >= Food.label.winfo_x():
            while list3[0] >= Food.label.winfo_x():
                print("fdkfj")
                list3[0] = list3[0] - 0.05

                parent1.place(x=list3[0], y=list3[1])

                print(list3[0])
                print(list3[1])
                wind.update()

        if list3[0] <= Food.label.winfo_x():
            while list3[0] <= Food.label.winfo_x():
                print(list3[0])
                print(list3[1])
                print("fdkfj")
                list3[0] = list3[0] + 0.05

                parent1.place(x=list3[0],y=list3[1])
                wind.update()

    hzom()
    zombie()