在 Python 3 上编写一个小程序。有一个矩形,它必须从墙壁(窗口的边框)反弹
check=False
from tkinter import*
rect_x=50#x0 of rect
rect_y=50#y0 of rect
rect_x1=rect_x+rect_x#x1 of rect
rect_y1=rect_y+rect_y#y1 of rect
rect_change_x=5#change X speed
rect_change_y=3#change Y speed
root=Tk()
while check==False:
if rect_y > 450 or rect_y < 0:
rect_change_y = rect_change_y * -1
if rect_x > 650 or rect_x < 0:
rect_change_x = rect_change_x * -1
rect_x+=rect_change_x#changing x
rect_y+=rect_change_y#changing y
rect_x1+=rect_change_x#changing x1
rect_y1+=rect_change_y#changing y1
c=Canvas(root,bg='yellow',width=700,height=500)
c.pack()
rect=c.create_rectangle(rect_x,rect_y,rect_x1,rect_y1,fill='black')
root.mainloop()
我猜想,一切都很好,但是当我运行这个程序时,什么也没有发生。Tkinter 窗口没有出现。它有什么问题,我哪里有错误?