|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#想显示宣传的电扇,先调用tkinter,制作了一个画布,绘制了一个静态的电扇,设置了一个按钮,希望调用zhuan()函数(通过循环,删除之前的电扇,绘制新电扇)想让它转起来。执行的时候,点按钮后一直没有转起来,是什么原因。有没有什么好的解决方案
from tkinter import *
class Fan:
def __init__(self):
window=Tk()
self.canvas1=Canvas(window,width=500,height=500,bg="white")
self.canvas1.pack()
self.canvas1.create_arc(100, 100, 400, 400, start=0 , extent=20 , fill="red", tags="Arc1")
self.canvas1.create_arc(100, 100, 400, 400, start=90 , extent=20 , fill="red", tags="Arc2")
self.canvas1.create_arc(100, 100, 400, 400, start=180, extent=20 , fill="red", tags="Arc3")
self.canvas1.create_arc(100, 100, 400, 400, start=270, extent=20 , fill="red", tags="Arc4")
b1=Button(window,text="zhuan",command=self.zhuan)
b1.pack()
window.mainloop()
def zhuan(self):
i=0
while True:
self.canvas1.delete("Arc1","Arc2","Arc3","Arc4")
self.canvas1.create_arc(100,100,400,400,start=i,extent=20,fill="red",tags="Arc1")
self.canvas1.create_arc(100, 100, 400, 400, start=90 + i, extent=20 , fill="red", tags="Arc2")
self.canvas1.create_arc(100, 100, 400, 400, start=180 + i, extent=20 , fill="red", tags="Arc3")
self.canvas1.create_arc(100, 100, 400, 400, start=270 + i, extent=20, fill="red", tags="Arc4")
i+=1
Fan()
tkinter刷新一下就行了
from tkinter import *
class Fan:
def __init__(self):
self.window=Tk()
self.canvas1=Canvas(self.window,width=500,height=500,bg="white")
self.canvas1.pack()
self.canvas1.create_arc(100, 100, 400, 400, start=0 , extent=20 , fill="red", tags="Arc1")
self.canvas1.create_arc(100, 100, 400, 400, start=90 , extent=20 , fill="red", tags="Arc2")
self.canvas1.create_arc(100, 100, 400, 400, start=180, extent=20 , fill="red", tags="Arc3")
self.canvas1.create_arc(100, 100, 400, 400, start=270, extent=20 , fill="red", tags="Arc4")
b1=Button(self.window,text="zhuan",command=self.zhuan)
b1.pack()
self.window.mainloop()
def zhuan(self):
i=0
while True:
self.canvas1.delete("Arc1","Arc2","Arc3","Arc4")
self.canvas1.create_arc(100,100,400,400,start=i,extent=20,fill="red",tags="Arc1")
self.canvas1.create_arc(100, 100, 400, 400, start=90 + i, extent=20 , fill="red", tags="Arc2")
self.canvas1.create_arc(100, 100, 400, 400, start=180 + i, extent=20 , fill="red", tags="Arc3")
self.canvas1.create_arc(100, 100, 400, 400, start=270 + i, extent=20, fill="red", tags="Arc4")
self.window.update()
i+=1
Fan()
|
|