python飞机大战移动模块

import tkinter as tk

def move_left(event):
    canvas.move(player, -10, 0)

def move_right(event):
    canvas.move(player, 10, 0)

def move_up(event):
    canvas.move(player, 0, -10)

def move_down(event):
    canvas.move(player, 0, 10)

root = tk.Tk()
root.title("飞机大战游戏")

canvas = tk.Canvas(root, width=500, height=500)
canvas.pack()

player = canvas.create_rectangle(225, 225, 275, 275, fill="red")

canvas.focus_set()  # 让canvas获取焦点,使键盘事件能够触发

canvas.bind("", move_left)    # 绑定左箭头键
canvas.bind("", move_right)  # 绑定右箭头键
canvas.bind("", move_up)        # 绑定上箭头键
canvas.bind("", move_down)    # 绑定下箭头键

root.mainloop()

你可能感兴趣的:(python,服务器,开发语言)