Simple 2d surface with arrow in python? Simple 2d surface with arrow in python? tkinter tkinter

Simple 2d surface with arrow in python?


Tkinter is an excellent choice for such a simple task. You almost certainly already have it installed, and the Canvas widget is remarkably powerful. It has built-in facilities to draw lines that have an arrow at the end, and rotation is very straight-forward.

Don't let "common knowledge" about Tkinter sway you -- it is a modern, stable, and extremely easy to use toolkit. You can't create the next photoshop or iMovie with it, but for most people and for most apps it is a very solid, pragmatic choice.

Here is a quick and dirty example:

import Tkinter as tkimport mathclass 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()


you might look at visual and/or vpython. http://www.vpython.org/Vpython claims to be 3-d programming for ordinary mortals. It's based on visual which I have used before and found easy to pick up.


The wxPython GUI toolkit (considered AFAIK better and more professional than TkInter anyways) has a rotate method for its Image class: http://wxpython.org/docs/api/wx.Image-class.html.

The Python Imaging Library (not a GUI toolkit, but an imaging library) likewise supports image rotation: http://effbot.org/imagingbook/image.htm.