Jump to content

User:Antosures

From Wikipedia, the free encyclopedia

Hello, Wikipedia dweller!

[edit]

On this page, I just share some stuff.

Here's some Python code to steal (i will add to this later):

import tkinter
import keyboard

root = tkinter.Tk()
player = tkinter.Frame(root)
px = player.winfo_x()
py = player.winfo_y()
player.configure(width='100', height='100')
player.pack()  # add this line to make the frame visible

def move():
    if keyboard.is_pressed("w"):
        px = player.winfo_x()  # get current x position
        py = player.winfo_y()  # get current y position
        player.place(x=px, y=py-5)  # move the frame up by 10 pixels
    if keyboard.is_pressed("s"):
        px = player.winfo_x()  # get current x position
        py = player.winfo_y()  # get current y position
        player.place(x=px, y=py+5)  # move the frame up by 10 pixels
    if keyboard.is_pressed("a"):
        px = player.winfo_x()  # get current x position
        py = player.winfo_y()  # get current y position
        player.place(x=px-5, y=py)  # move the frame up by 10 pixels
    if keyboard.is_pressed("d"):
        px = player.winfo_x()  # get current x position
        py = player.winfo_y()  # get current y position
        player.place(x=px+5, y=py)  # move the frame up by 10 pixels

    # call the move() function again after a short delay
    root.after(5, move)
root.title("Moving Simulator")
root.configure(bg="green")
# start the movement loop
move()
root.mainloop()