Trying to update position of lines in Tkinter based off of text file
<p>I am creating a Tkinter program that creates a canvas that shows a vehicles position according to an angle that is saved to a text file. The problem that I have is that the program only reads the text file when it starts and doesn't continue checking. I know that it should be fairly simple but I have looked at many sites and cannot find a way to do this. Here is my code </p>

<pre><code>            from Tkinter import *
            import math
            import time

            root = Tk()
            root.geometry("800x480")
            root.configure(background='darkgrey')
            content = Frame(root,)

            #Dimensions of Window
            w = 800
            h = 480

            #Get Angle
            file_angle = open("current_angle.txt")
            #read file and remove "/n" from the end of the string
            string_angle = ((file_angle.read())[:-2])
            #Convert string to a number
            read_angle = float(string_angle)

            if read_angle &gt; 90 or read_angle &lt;-90:
                deg_angle = read_angle - 180

            else:
                deg_angle = read_angle

            angle = math.radians(deg_angle)
            swath_width = w / 5

            if deg_angle &gt; -90 and deg_angle &lt; 90:
                #Center Line
                centertopx = (w/2) + ((h / 1.5) * math.tan(angle))
                centertopy = 0
                centerbottomx = (w/2) + ((h - (h / 1.5)) * math.tan(-1 * angle))
                centerbottomy = h

            if deg_angle == 90 or deg_angle == -90:
                centertopx = 0
                centertopy = h / 2
                centerbottomx = w
                centerbottomy = h / 2

            #Create Guidance Map
            livemap = Canvas(root, width=w, height=h)
            #Outline of map
            livemap.create_rectangle(0,0,w,h, outline="black", width=5, fill="#9E9E9E")


            #Drawing lines
            livemap.create_line(centertopx, centertopy, centerbottomx, centerbottomy, fill="red", width=4)

            #stationary parts of map
            #Triangle that represents vehicle
            livemap.create_polygon(
                ((w/2)-(w * 0.04)),((h / 1.5)+(h * 0.1)),((w/2)+(w *                    0.04)),((h / 1.5)+(h * 0.1)),(w/2),(h / 1.5),
                outline="black", fill="darkorange", width=2)
            livemap.create_line((w/2),((h / 1.5)+(h*0.07)),(w/2),(h / 1.5),fill="black", width=2)
            livemap.create_polygon(((w/2)-(w * 0.04)),((h / 1.5)+(h * 0.1)),((w/2)+(w * 0.04)),((h / 1.5)+(h * 0.1)),(w/2),((h / 1.5)+(h*0.07)),
                outline="black", fill="darkorange", width=2)

            #Put canvas into window
            livemap.grid(column=0, row=0, columnspan=4, rowspan=4)

            root.mainloop()
</code></pre>

<p>Use <code>root.after(miliseconds, function_name)</code> to run periodically function which will read file again and move line on canvas. </p>

<p>In code I create line only once (before vehicle) and later I change only line position.</p>

<pre><code>from Tkinter import *
import math
import time

w = 800
h = 480

# --- functions ---

def update_line():

    deg_angle = open("current_angle.txt")
    deg_angle = deg_angle.read()[:-2]
    deg_angle = float(deg_angle)

    if deg_angle &gt; 90 or deg_angle &lt;-90:
        deg_angle -= 180

    if deg_angle == 90 or deg_angle == -90: # you need 
        centertopx = 0
        centertopy = h / 2
        centerbottomx = w
        centerbottomy = h / 2
    else:    # deg_angle &gt; -90 and deg_angle &lt; 90:

        angle = math.radians(deg_angle)

        #Center Line
        centertopx = (w/2) + ((h/1.5)*math.tan(angle))
        centertopy = 0
        centerbottomx = (w/2) + ((h - (h/1.5))*math.tan(-angle))
        centerbottomy = h

    # move line
    livemap.coords(line, centertopx, centertopy, centerbottomx, centerbottomy)

    # repeat after 200 ms (0.2s)
    root.after(200, update_line)

# --- main ---

root = Tk()
root.geometry("800x480")
root.configure(background='darkgrey')

content = Frame(root,)
livemap = Canvas(root, width=w, height=h)
livemap.create_rectangle(0, 0, w, h, outline="black", width=5, fill="#9E9E9E")

# create line (without angle) before vehicle
line = livemap.create_line(w/2, 0, w/2, h, fill="red", width=4)

#Triangle that represents vehicle
livemap.create_polygon(
    (w/2)-(w*0.04), (h/1.5)+(h*0.1),
    (w/2)+(w*0.04), (h/1.5)+(h*0.1),
    w/2, h/1.5,
    outline="black", fill="darkorange", width=2)

livemap.create_line(w/2, (h/1.5)+(h*0.07), w/2, h/1.5, fill="black", width=2)

livemap.create_polygon(
    (w/2)-(w*0.04), (h/1.5)+(h*0.1),
    (w/2)+(w*0.04), (h/1.5)+(h*0.1),
    w/2, (h/1.5)+(h*0.07),
    outline="black", fill="darkorange", width=2)

livemap.grid(column=0, row=0, columnspan=4, rowspan=4)

# update line first time
update_line()

root.mainloop()
</code></pre>

python tkinter tkinter-canvas