Я работаю над экраном чата и успешно вставил Scrollview и макет блока внутри него, но когда вызывается функция отправки сообщения, он добавляется в Scrollview, но он переписывает то, что уже написано в Scrollview. я хочу, чтобы при добавлении виджета в вид прокрутки он добавлялся к предыдущим элементам вида скролла, а не переопределял его. Вот код из моего python файла.
class Chat(Screen):
def on_enter(self, *args):
app = App.get_running_app()
self.chatdestination = Label(
text=firebase.get("/users/" + app.localId, 'first name') + " " + firebase.get('/users/' + app.localId,
'last name'),
pos_hint={"center_x": 0.5, "center_y": 0.95}, size_hint=[0.8, 0.1], color=(0, 0, 0, 1),
font_name="fonts/Qanelas-Light.otf")
self.add_widget(self.chatdestination)
def __init__(self, **kwargs):
super(Chat, self).__init__(**kwargs)
self.localId = None
self.messagebutton = Button(text="Send", font_size = 20, font_name= "fonts/Qanelas-Heavy.otf", background_color= (0.082, 0.549, 0.984, 1.0), background_normal= '', pos_hint= {"right": 1,"down": 1}, size_hint= [0.2, 0.1])
self.messagebutton.bind(on_release = self.send_message)
self.add_widget(self.messagebutton)
self.messagetextinput = TextInput(width=Window.size[0]*0.8, hint_text= "Write a message", font_name= "fonts/Qanelas-Light.otf", size_hint= [0.8, 0.1], pos_hint= {"left": 1,"down": 1})
self.add_widget(self.messagetextinput)
Window.bind(on_key_down=self.on_key_down)
Clock.schedule_once(self.focus_text_input, 1)
def on_key_down(self, instance, keyboard, keycode, text, modifiers):
if keycode == 40:
self.send_message(None)
def send_message(self, _):
app = App.get_running_app()
message = self.messagetextinput.text
if len(message) > 0:
database.child("messages").child(app.localId).update({self.localId: message})
self.chatbubble = Button(text=self.messagetextinput.text, background_color = [0.082, 0.549, 0.984, 1.0], background_normal = "",
pos_hint= {"center_x": 1}, color = (1, 1, 1, 1))
self.chatbubble.size = self.chatbubble.texture_size
self.ids.chatlayout.add_widget(self.chatbubble)
self.ids.scrollview.scroll_to(self.chatbubble)
self.messagetextinput.text = ""
Clock.schedule_once(self.focus_text_input, 0.1)
def focus_text_input(self, _):
self.messagetextinput.focus = True
class MyApp(App):
refresh_token_file = "refresh_token.txt"
placementtext = None
id1 = None
local1d = None
placementid = None
notification = None
def build(self):
self.refresh_token_file = self.user_data_dir + self.refresh_token_file
self.thefirebase = MyFireBase()
return sm
Вот мой код из моего файла kivy
<Chat>
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
ScrollView:
id: scrollview
pos_hint: {"center_x": 0.5, "center_y": 0.5}
size_hint: 1, 0.8
canvas.before:
Color:
rgba: 0, 0, 0, 0
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
id: chatlayout
orientation: "vertical"
spacing: 5
padding: 10, 10
size_hint_y: None
Любая помощь будет оценена