Я думаю, что в наше время kivy используется меньше. Никто не ответил. Поэтому я каким-то образом нашел альтернативу тому, чего я хотел достичь.Я добавил кнопку «Обновить», которая снова запускает всю функцию, которая включает выборку значений из файла и снова рисует график. Таким образом, всякий раз, когда значения обновляются в файле, мы получаем график для этого.
Воткод python 3.
class Graph(FigureCanvasKivyAgg):
def __init__(self,*args,**kwargs):
FigureCanvasKivyAgg.__init__(self,f)
pullData = open("TimeLatitude.txt", "r").read()
dataList = pullData.split('\n')
xList = []
yList = []
pullData2 = open("TimeLongitude.txt", "r").read()
dataList2 = pullData2.split('\n')
xList2 = []
yList2 = []
for eachLine in dataList:
if len(eachLine) > 1:
x, y = eachLine.split(',')
xList.append(int(x))
yList.append(int(y))
for eachLine in dataList2:
if len(eachLine) > 1:
x, y = eachLine.split(',')
xList2.append(int(x))
yList2.append(int(y))
a.plot(xList, yList, "#00A3E0", label="Latitude")
a.plot(xList2, yList2, "#183A54", label="Longitude")
a.legend(bbox_to_anchor=(0, 1.02, 1, .102), loc=3,
ncol=2, borderaxespad=0)
title = "Oxymora Mars Rover Coordinates\nLast Longitude : " + str(
yList2[len(yList2) - 1]) + "\nLast Latitude : " + str(yList[len(yList) - 1])
a.set_title(title)
def animate(self):
pullData = open("TimeLatitude.txt", "r").read()
dataList = pullData.split('\n')
xList = []
yList = []
pullData2 = open("TimeLongitude.txt", "r").read()
dataList2 = pullData2.split('\n')
xList2 = []
yList2 = []
for eachLine in dataList:
if len(eachLine) > 1:
x, y = eachLine.split(',')
xList.append(int(x))
yList.append(int(y))
for eachLine in dataList2:
if len(eachLine) > 1:
x, y = eachLine.split(',')
xList2.append(int(x))
yList2.append(int(y))
a.clear()
a.plot(xList, yList, "#00A3E0", label="Latitude")
a.plot(xList2, yList2, "#183A54", label="Longitude")
a.legend(bbox_to_anchor=(0, 1.02, 1, .102), loc=3,
ncol=2, borderaxespad=0)
title = "Oxymora Mars Rover Coordinates\nLast Longitude : " + str(
yList2[len(yList2) - 1]) + "\nLast Latitude : " + str(yList[len(yList) - 1])
a.set_title(title)
self.draw()
и вот соответствующий код kivy.
<MainScreen>:
name: "main"
FloatLayout:
Graph
id:gr
Button:
on_release: gr.animate()
text: "Refresh"
font_size: 15
size_hint:0.068,0.05
pos_hint: {"x":0,"top":0.8}
color: 1,0,1,1
Итак, наконец, после запуска моего полного кода приложение kivy выглядит так - Изображение приложения Kivy