"""风火轮走迷宫项目核心代码,本人去年计划的一个小项目的原型代码,修改turtle.py让图形角色可以直接旋转.
启动程序后,输入代码,指挥风火轮移动! 可以把它完善为一个完整的编程入门教育游戏.
下面的turtle模块为本人修改后的. 如果你要问迷宫呢? 这就得靠你自己了!
"""
from turtle import TurtleScreen, RawTurtle, TK
def run_code():
code_string = text_code.get("1.0",'end-1c')
"禁用运行按钮"
run_command.config(state='disabled')
exec(code_string)
"启用运行按钮"
run_command.config(state='normal')
def main():
global text_code
global cat
global screen
global run_command
default_code = """for _ in range(4):
cat.fd(100)
cat.rt(90)
"""
root = TK.Tk()
root.geometry("740x660")
root.title("风火轮走迷宫项目核心代码 www.lixingqiu.com")
cv1 = TK.Canvas(root, width=540, height=420, bg="#000000")
cv1.place(x = 190,y = 10)
screen = TurtleScreen(cv1)
screen.bgcolor(0.85, 0.85, 1)
text_code=TK.Text(root,width=40,height=10,font=("黑体", 16, "normal"))
text_code.insert("1.0",default_code)
text_code.place(x = 190,y = 440)
run_command = TK.Button(root,text='运行',command=run_code,font=('黑体',20),bg='white',fg='red')
run_command.place(x = 650,y = 480)
#screen.addshape("风火轮子logox.png") # 支持png不需注册即可直接使用
cat = RawTurtle(screen,visible=False)
cat.color("red")
cat.width(3)
cat.shape("风火轮子logox.png")
cat.rotatemode("all") # 新增旋转模式,角色可360度旋转
cat.st() # 显示小猫
return "EVENTLOOP"
if __name__ == '__main__':
main()
TK.mainloop() # 进入事件循环
