嗨,到目前为止,我正在尝试使用 wasd 移动对象,直到让 wasd 启动一个函数,但我不知道如何实际移动对象。谢谢
希望有人能告诉我如何做到这一点
我还试图让较小的椭圆向右飞过屏幕
`
#new_game.py
from tkinter import *
import random
r = random
class window_one:
def __init__ (self):
Button(main_window,text="Start",command=self.start).grid()
Button(main_window,text="Quit",command=self.quit).grid()
Button(main_window,text="ball",command=self.dodge).grid()
def quit(self):
main_window.destroy()
def start(self):
x_val1 = 30
x_val2 = x_val1 - 20
y_val1 = 175
y_val2 = y_val1 + 20
self.dave = canvas.create_rectangle(30,175,10,195,fill="green")
self.dodge
canvas.update()
def dodge(self):
colorl = ["red","blue","green","yellow","purple"]
y_val = r.randint(1,390)
color = r.choice(colorl)
canvas.create_oval(590,y_val,600,y_val+10,fill = color)
def up(self):
Canvas.move(start.dave,30,50)
def down(self):
print()
def left(self):
print()
def right(self):
print()
main_window = Tk()
canvas = Canvas(main_window,width=600,height=390,bg = "#ffffff")
canvas.grid()
window_one()
main_window.bind("<KeyPress-Left>",window_one.left)
main_window.bind("<KeyPress-Right>",window_one.right)
main_window.bind("<KeyPress-Up>",window_one.up)
main_window.bind("<KeyPress-Down>",window_one.down)`