所以我试图制作一个圆圈解决迷宫的程序。到目前为止,我可以对迷宫进行生成,并且可以给圆圈提供移动的坐标,但我对Tkinter来说是一个新手,并且不确定如何使圆圈移动(比如说每2秒)。目前所做的只是展示第一个案例,我不认为我将top.mainloop()
置于应有的位置。
代码(缩写为GUI上的榕):
import string
import random
import tkinter
from tkinter import *
from enum import Enum
class Direction(Enum):
up=1
down=2
left=3
right=4
myFile = open("labyrinth.txt","r")
lab=myFile.read()
"get number of lines/rows & columns: LABYRINTH MUST BE SQUARE"
cols=rows=len(lab.splitlines())
"GUI"
"build the output window"
top = Tk()
C = Canvas(top, bg = "white", height = rows*40, width = cols*40)
lab=lab.splitlines()
maze=[]
for i in range(rows):
maze.append([0]*(cols))
for y in range (rows):
for x in range (cols):
maze[y][x]=lab[y][x]
if(maze[y][x]=="1"):
myColor="white"
elif(maze[y][x]=="0"):
myColor="black"
elif(maze[y][x]=="3"):
myColor="red"
else:
myColor="green"
C.create_polygon(x*40, y*40, x*40+40, y*40, x*40+40 ,y*40+40, x*40, y*40+40, fill=myColor)
robot=C.create_oval(0, 0, 40, 40, fill="yellow")
C.pack()
top.mainloop()
d=Direction.down
"move"
dest=[]
dest=position
while(stepsTaken<nbMaxSteps):
dest=[]
dest.append(position[0]) #x does not change
dest.append(position[1]-1) #y decreases by 1
top.after(2000, C.move(robot, dest[0]*40, dest[1]*40))
我哪里错了?
抱歉,如果已经提出这个问题,我确实进行了搜索,但无法找到关于top.mainloop()
应该在哪里的答案。