学习python编程,在新东方少儿编程官网的自由创作平台做的一些作品。
可以在线运行,效果如下(在新页面中打开链接):
代码如下(用到平台自定义的xdf库):
from xdf import * class MyKeyBoard: def __init__(self, x, y, w): hw = w / 2 hhw = w * 0.75 self.arr = [ box(x, y - w, w, w, "white", "red"), text("↑", x + hw, y - w + hhw, w, "center", "red"), box(x, y, w, w, "white", "red"), text("↓", x + hw, y + hhw, w, "center", "red"), box(x - w, y, w, w, "white", "red"), text("←", x - hw, y + hhw, w, "center", "red"), box(x + w, y, w, w, "white", "red"), text("→", x + w + hw, y + hhw, w, "center", "red"), ] self.arr[0].tap=self.clickUp self.arr[2].tap=self.clickDown self.arr[4].tap=self.clickLeft self.arr[6].tap=self.clickRight delay(self.loop, 100) def loop(self): for i in range(len(self.arr)): self.arr[i].front() delay(self.loop, 100) def onKeydown(self, keyCode, key): try: keydown(keyCode, key) except e: pass def clickUp(self): self.onKeydown(38, "ArrowLeft") def clickDown(self): self.onKeydown(40, "ArrowDown") def clickLeft(self): self.onKeydown(37, "ArrowLeft") def clickRight(self): self.onKeydown(39, "ArrowRight") MyKeyBoard(768-200, 1024-100, 100) def keydown(keyCode, key): print(keyCode, key)
也可以下载代码,本地python环境运行(用pygame封装了xdf库)。
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。