寫一點PROGRAMM上的Python 3 有一個矩形,它已經從牆壁(窗口的邊框)與Tkinter的
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窗口沒有出現。 它有什麼問題,我有一個錯誤?
要顯示一些內容,您必須輸入事件回調。但是你所做的一切是運行一個無限循環。使用異步編程。用一些定時器安排下一個油漆。 –