I am kinda new to library Tkinter on python,
I am trying to animate actual time and simulated time of a vehicle on road. The road's segments is constructed using the GPS data.For example, below is my dataframe:
----------------------------------------------------
Easting | Northing | ActualTime | SimulatedTime
----------------------------------------------------
311257 | 6408368 | 5 | 4.5
311300 | 6408400 | 5 | 4
311305 | 6408410 | 5 | 4.2
......
I have 2 questions: 1. How do I reverse the y-coordinate on tkinter canvas? 2. How do I animate the objects moving with different time?
What I am currently doing is below:
from tkinter import *
import pandas as pd
from sklearn import preprocessing
data = pd.read_csv('data.csv')
east = data[['Easting']].values
north = data[['Northing']].values
min_max_scaler = preprocessing.MinMaxScaler()
east_scaled = min_max_scaler.fit_transform(east)
north_scaled = min_max_scaler.fit_transform(north)
data['N_Easting'] = east_scaled
data['N_Northing'] = north_scaled
data['shiftX'] = 0
data['shiftY'] = 0
for i in range(1, len(data)):
data['shiftX'].loc[i] = data['N_Easting'].loc[i] - data['N_Easting'].loc[i-1]
data['shiftY'].loc[i] = data['FNorthing'].loc[i] - data['FNorthing'].loc[i-1]
master = Tk()
canvas_width = 1100
canvas_height = 1100
w = Canvas(master, width = canvas_width, height = canvas_height)
w.pack()
# creating the road segment
for i in range (0, len(data)-1):
b = w.create_line(data['N_Easting'].loc[i], data['N_Northing'].loc[i], data['N_Easting'].loc[i+1], data['N_Northing'].loc[i+1], width = 10)
a = w.create_oval(data['N_Easting'].loc[0]-5, data['N_Northing'].loc[0]-5, data['N_Easting'].loc[0]+5, data['N_Northing'].loc[0]+5, fill = 'red')
s = w.create_oval(data['N_Easting'].loc[0]-5, data['N_Northing'].loc[0]-5, data['N_Easting'].loc[0]+5, data['N_Northing'].loc[0]+5, fill = 'yellow')
for i in range(1, len(data)):
w.move(s, data['shiftX'].loc[i], data['shiftY'].loc[i])
master.update()
time.sleep(data['ActualTime'].loc[i])
for i in range(1, len(data)):
w.move(a, data['shiftX'].loc[i], data['shiftY'].loc[i])
master.update()
time.sleep(data['SimulatedTime'].loc[i])
mainloop()
However, by executing the scripts above, the actual object is moving and traverse the road verse, after it finishes the trip, then the simulated object starts to traverse. Can anyone help me so that the two objects are moving together that I can animate and compare the travelling time of actual and simulated vehicle?
Thanks in advance!