我的目标是创建一个模拟赛马的程序,我的问题是当我用 Tkinter 绘制时,我得到一个空白画布。我确定这是一些明显的错误,但我找不到。有什么帮助吗?
class Horse ():
def __init__ (self, color, number, slot):
self.xPos = 0
self.yPos = self.xPos - 59
self.move = 0
self.slot = slot
self.size = 40
self.color = color
self.number = number
def horseMove (self):
self.Erase()
self.move= random.randint(20,80)
self.xPos = self.xPos + self.move
self.Draw()
myCanvas.update()
return self.xPos
def Erase (self):
myCanvas.create_rectangle (self.xPos, self.yPos, self.xPos + 75, self.yPos + 40, fill = 'white', outline ='white')
def Draw (self):
myCanvas.create_oval (self.xPos, self.yPos, self.xPos + 75, self.yPos + 40, fill = color)
myCanvas.create_text (self.xPos + 35, self.yPos, text = self.number, fill = 'blue', font = ("Times","17"))
time.sleep (0.5)
这是我的课程代码
Horses= []
slot=0
for i in range (0,3):
number=input("what is the horses number: ")
color=input("what is the horses color: ")
slot += 1
animal=Horse(color, number, slot)
Horses.append(animal)
import random
from tkinter import *
import time
root = Tk()
myCanvas = Canvas (root, width =1000, height=1000, background='white')
myCanvas.pack()
while True:
for i in range (0,len(Horses)):
animal.horseMove()
这是我的主线