I am transferring data from the server to the label widget. I update the window every second so that new data from the server is visible in the window without restarting the window. Sorry, I'm new to working with kivymd
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.uix.boxlayout import BoxLayout
from kivymd.app import MDApp
from socket import *
from kivymd.uix.label import MDLabel
class TestApp(MDApp):
def build(self):
client = socket(
AF_INET, SOCK_STREAM
)
client.connect(('192.168.5.99', 7000))
data = client.recv(1024)
msg = data.decode('utf-8')
label1 = MDLabel(font_style="H5", pos_hint={'center_x': 0.5, 'center_y': 0.5})
Clock.schedule_interval(msg, 1)
return label1
TestApp().run()
I tried updating the data in an infinite loop While True. I expect my widget to be constantly updated and receive data from the server without errors.
In your code, msg
will be a str
, but Clock.schedule_interval
expects a Callable (a function) as the first parameter.
You need to define a function or lambda expression that handles whatever you want to happen when the scheduled event occurs. See the documentation for more information.
Further, you need to look into setting up the receiving socket and storing the received data as it arrives. Then, use that data in the callable that Clock.schedule_interval
triggers.