'Code will not run after a while true loop

why doesn't code run after a while True loop and how do i fix this?

example code:

while True:

x += 1

print(x, "is the variable X's value") <-- this does not run :(

how can this be fixed?

my code:

gui = Tk()
gui.geometry('400x200')

player_x = 0
player_y = 0
global key
key = getkey()


def Movement():
    player_x = 0
    player_y = 0
    while True:
        if getkey() == 'w' or key == keys.UP:
            player_y += 1
            print(player_x, ", ", player_y)

        if getkey() == 's' or key == keys.DOWN:
            player_y -= 1
            print(player_x, ", ", player_y)

        if getkey() == 'd' or key == keys.RIGHT:
            player_x += 1
            print(player_x, ", ", player_y)

        if getkey() == 'a' or key == keys.LEFT:
            player_x -= 1
            print(player_x, ", ", player_y)
    return


#gui
playerimage = PhotoImage(file='player.png')


def everyframe():
    player.place(x=player_x, y=player_y)
    gui.after(100, everyframe)


def startscript():
    global player
    player = Button(gui, image=playerimage, command=print("boop!"))
    print("started")
    everyframe()


Movement()

startbutton = Button(gui, text="START", command=startscript)
startbutton.pack(side=BOTTOM)
gui.mainloop()

In this, the tkinter window is not changed because it is placed under a while True loop. I cannot change where it is put because I will get error: local variable referenced before assignment error. is there a different loop that I can use that will still run the code after it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source