对于这样一个简单的任务,Tkinter是一个很好的选择。您几乎可以肯定已经安装了它,Canvas小部件非常强大。它有内置的设施,可以画出末端有箭头的线条,而且旋转非常笔直。在
不要让关于Tkinter的“常识”左右你,它是一个现代、稳定、极易使用的工具箱。你不能用它来创建下一个photoshop或iMovie,但对大多数人和大多数应用来说,这是一个非常可靠、实用的选择。在
下面是一个快速而肮脏的例子:import Tkinter as tk
import math
class ExampleApp(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.canvas = tk.Canvas(self, width=400, height=400)
self.canvas.pack(side="top", fill="both", expand=True)
self.canvas.create_line(200,200, 200,200, tags=("line",), arrow="last")
self.rotate()
def rotate(self, angle=0):
'''Animation loop to rotate the line by 10 degrees every 100 ms'''
a = math.radians(angle)
r = 50
x0, y0 = (200,200)
x1 = x0 + r*math.cos(a)
y1 = y0 + r*math.sin(a)
x2 = x0 + -r*math.cos(a)
y2 = y0 + -r*math.sin(a)
self.canvas.coords("line", x1,y1,x2,y2)
self.after(100, lambda angle=angle+10: self.rotate(angle))
app = ExampleApp()
app.mainloop()