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()
Run Code Online (Sandbox Code Playgroud)
wxPython GUI 工具包(至少被认为比 TkInter 更好、更专业)的 Image 类有一个旋转方法:http ://wxpython.org/docs/api/wx.Image-class.html 。
Python 成像库(不是 GUI 工具包,而是成像库)同样支持图像旋转: http: //effbot.org/imagingbook/image.htm。