Kivy does not update the refreshed data on the screen. If i restart the app, i can see the new data after calculation. I want to see refreshed data on the screen after the calculation is done, without restarting the program again.
When i run the app, datas() function pulls the json file at the first time and also when i on the second calculation screen, before calculation, the Clock.schedule_once(self.datas) pulls the data again as well but sill i can see the refreshed names on the screen.
PY File:
data.json File
Please create a data.json file and PLEASE CHANGE THE LOCATION!!!!!!!!!!!!!!!!! in def datas(self, *args): with open ("C:\Users\Messi\Desktop\Python\Projects\Football Tips\Kivy\Testing Bugs\Test1\data.json", "r") as dosya:
{"home": ["Manchester City", "Arsenal"]}
Video Of The Problem
https://www.youtube.com/watch?v=mMwryGLQ5SQ
Thanks for your help
In the __init__() you are assigning self.data = self.datas(), and then using self.data to display the info. The var self.data is only getting updated when the app first runs. You could make the changes as below. See the highlighted areas.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.metrics import dp
from kivy.clock import Clock
import json
class Test(BoxLayout):
# def __init__(self, **kwargs):
# super(Test, self).__init__(**kwargs)
# self.data = self.datas()
# Homepage Screen
def homepage(self, screenmanager):
screenmanager.current = 'homepage_screen'
Clock.schedule_once(self.clear_widgets)
# Clear Widgets
def clear_widgets(self, *args):
for child in [child for child in self.ids.gridsonuc.children]:
self.ids.gridsonuc.remove_widget(child)
# Under Over Screen
def second(self, screenmanager):
screenmanager.current = 'second_screen'
Clock.schedule_once(self
.clear_widgets)
# Clock.schedule_once(
# self.datas) # Before calculation, each time app pulls data again, but Kivy Does Not Update The Refreshed Data in The Screen!
Clock.schedule_once(self.calculate)
# Calculation
def calculate(self, *args):
data = self.datas()
for i in data['home']:
box = BoxLayout(size_hint_y=None, height=dp(50))
hometeams = Label(text=f'{[i]}', font_name='Roboto', font_size=dp(15), size_hint=(0.225, 1),
halign='center', bold=True)
box.add_widget(hometeams)
self.ids.gridsonuc.add_widget(box)
def datas(self, *args):
# PLEASE CHANGE THE LOCATION!!!!!!!!!!!!!!!!!
with open('data.json') as dosya:
dataApi = json.load(dosya)
print('datas updated')
return dataApi
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d6243cbc-dcd4-4254-bc4d-1b0710df3b6bn%40googlegroups.com.