fromtkinterimport*importrandomimporttimeclassBall:def__init__(self,canvas,color):self.canvas=canvasself.id=canvas.create_oval(10,10,25,25,fill=color)self.canvas.move(self...
from tkinter import*
import random
import time
class Ball:
def __init__(self, canvas, color):
self.canvas = canvas
self.id = canvas.create_oval(10,10,25,25,fill=color)
self.canvas.move(self.id, 245, 100)
def draw(self):
self.canvas.move(self.id,0,-1)
#____________________________________________________________
tk = Tk()
tk.title("Game")
tk.resizable(0,0)
tk.wm_attributes("-topmost",1)
canvas = Canvas(tk,width = 500,height=400,bd=0,highlightthinckness=0)
canvas.pack()
tk.update()
#____________________________________________________________
ball = Ball(canvas,'red')
while 1:
ball.draw()
tk.update_idletasks()
tk.update()
只写了一半,是看书上的,不知道为什么运行的时候没有小球出现,哪里错了?谢谢
展开