python kivy asyncio ошибка при запуске приложения
Пишу небольшой мессенджер на питоне при помощи kivy и asyncio. При запуске появляется ошибка
AttributeError: 'MyApp' object has no attribute 'parent'.
import asyncio
from asyncio import transports
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.app import async_runTouchApp
Window.size = (400,800)
class ClientProtocol(asyncio.Protocol):
transport: transports.Transport
window: 'Chat'
def __init__(self, chat):
self.window = chat
def data_received(self, data: bytes):
print(data)
decoded = data.decode()
self.window.label.text = decoded
def connection_made(self, transport: transports.Transport):
self.window.label.text = "Успешно подключились, введите логин"
self.transport = transport
def connection_lost(self, exception):
self.window.label.text = "Вы отключены от сервера"
class Chat(BoxLayout):
protocol: ClientProtocol
def __init__(self):
super().__init__()
def send_message(self):
message = self.textinput.text()
self.textinput.clear()
self.protocol.transport.write(message.encode())
def create_protocol(self):
self.protocol = ClientProtocol(self)
return self.protocol
async def start(self):
loop = asyncio.get_running_loop()
coroutine = loop.create_connection(
self.create_protocol,
"127.0.0.1",
8888
)
await asyncio.wait_for(coroutine, 1000)
class MyApp(App):
def build(self):
return Chat()
loop = asyncio.get_event_loop()
app = loop.run_until_complete((
async_runTouchApp(MyApp(), async_lib='asyncio')))
loop.create_task(app.start())
loop.run_forever()
loop.close()
kv файл
<Chat>:
button:button
label:label
textinput:textinput
BoxLayout:
orientation:"vertical"
Label:
id:label
TextInput:
id:textinput
size_hint: 1,1
Button:
id:button
text: "Send"
size_hint:1,0.3