Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在kivy中创建聊天页面时遇到几个问题_Python_Kivy - Fatal编程技术网

Python 在kivy中创建聊天页面时遇到几个问题

Python 在kivy中创建聊天页面时遇到几个问题,python,kivy,Python,Kivy,我在处理聊天页面时遇到了一些问题,我正在尝试将聊天框设置为文本大小加上一个小空间,但我在这样做时遇到了问题,而且聊天框在屏幕外重叠,我希望日期戳直接位于每个聊天框的下方,但我在这样做时也遇到了一些问题。这是代码,下面是我目前情况的图片。我真的很感激你的帮助 def send_message(self, _): app = App.get_running_app() message = self.messagetextinput.text if l

我在处理聊天页面时遇到了一些问题,我正在尝试将聊天框设置为文本大小加上一个小空间,但我在这样做时遇到了问题,而且聊天框在屏幕外重叠,我希望日期戳直接位于每个聊天框的下方,但我在这样做时也遇到了一些问题。这是代码,下面是我目前情况的图片。我真的很感激你的帮助

 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( background_color = [0.082, 0.549, 0.984, 1.0], background_normal = "",
                                      pos_hint= {"center_x": 1}, color = (1, 1, 1, 1), size_hint_y = None, halign = "left", valign = "middle", text_size = (290, 40), font_name = "fonts/Qanelas-Regular.otf" )
            self.now = datetime.now()
            self.dt_string = self.now.strftime("%H:%M:")
            self.timestamp = Label(text = str(self.dt_string),  pos_hint= {"center_x": 1}, color = (0, 0, 0, 1), size_hint = (.8, .1))

            self.chatbubble.text = self.messagetextinput.text
            self.ids.chatlayout.add_widget(self.chatbubble)
            self.add_widget(self.timestamp)
            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

用一堆关于文本长度的if语句解决了这个问题,根据文本的长度,聊天泡泡的大小将进行调整,而聊天框下没有显示时间的原因是因为我错误地将其添加到了scrollview中,而不是聊天框所在的boxlayout中。

用一堆关于文本长度的if语句解决了这个问题,根据文本的长度,聊天气泡的大小将进行调整,而聊天框下没有显示时间的原因是因为我错误地将其添加到scrollview中,而不是聊天框所在的boxlayout中