Simple 2d surface with arrow in python?

I have not worked in python before. I need to make a really simple 2-dimensional surface where I can place the arrow and then change the position and angle of the arrow.

I started to create something like this in tkinter, but as I understand it, you cannot rotate images. In my opinion, only polygons can be rotated. It seems a little harder to draw an arrow like a polygon.

Are there any other tools that are more suitable for such simple things?

thank

+5
source share
3 answers

Tkinter - . , Canvas . ​​, .

" " Tkinter - , . 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()
+5

/ . http://www.vpython.org/ Vpython , 3- . , .

+1

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

The Python image library (not the GUI toolkit, but the image library) also supports image rotation: http://effbot.org/imagingbook/image.htm .

0
source

All Articles