我想做一个简单的聊天流。我正在努力的是让聊天消息左对齐,并根据窗口大小动态包装文本。在
这个想法是让聊天信息在网格布局中显示为标签。在
class ChatMessage(Label):
def __init__(self, *args, **kwargs):
super(ChatMessage, self).__init__(*args, **kwargs)
self.text_size = self.size
self.halign = 'left'
class Root(ScreenManager):
def __init__(self, *args, **kwargs):
super(ScreenManager, self).__init__(*args, **kwargs)
self.ids.chatstream.bind(minimum_height=self.ids.chatstream.setter('height'))
self.add_message()
def add_message(self):
for x in xrange(50):
label = ChatMessage(text='Im still not completely sure I understand the mechanisms at work here, though.. Im still not completely sure I understand the mechanisms at work here, though.. Im still not completely sure I understand the mechanisms at work here, though.' + str(x))
self.ids.chatstream.add_widget(label)
self.ids.scroller.scroll_y = 0
kv文件:
^{pr2}$
设置聊天消息实例的大小,例如
同时删除python大小中的text_size设置。如果将halign设置为kv,则可以完全删除
__init__
。在相关问题 更多 >
编程相关推荐