【发布时间】:2020-07-09 14:16:58
【问题描述】:
我正在制作一个可以从不同网站获取文章的网络爬虫。为此,我将文章小部件动态添加到它们各自的 GridLayouts 中。但是,有些屏幕上的文章是均匀分布的,而另一些则是零星分布的。似乎文章越长,空间就越少。下面是我认为相关的代码的 sn-ps(我会包括所有内容,但它是 1300 多行)。
例子:
良好的间距
间距不好
Python:
def text_collision(self):
labels = [i for i in self.news_articles.children]
for label in labels:
font_instance = 35
label.size = label.texture_size
if label.collide_point(*label.to_widget(*Window.mouse_pos)):
animation = Animation(font_size=font_instance + 2, s=1 / 60, duration=.06)
label.color = (.96, .60, .61, 1)
if label.count == 0:
animation.start(label)
label.count += 1
else:
label.count = 0
Animation.cancel_all(label)
label.color = (1, 1, 1, 1)
label.font_size = font_instance
def articles(self):
titles = self.csv_load()[0]
links = self.csv_load()[1]
for lnk, items in zip(links, titles):
if len(items.strip()) == 0 or len(lnk.strip()) == 0:
continue
article_widget = Label(text="[ref={}][b]{}[/b][/ref]".format(lnk, items), markup=True,
font_size=35, text_size=(700, None), halign='left', size_hint_y=None)
self.news_articles.add_widget(article_widget)
article_widget.on_ref_press = self.openlink
基维:
ScrollView:
do_scroll_x: False
do_scroll_y: True
pos: (50, -140)
smooth_scroll_end: 5
GridLayout:
id: articles
cols: 1
col_default_width: 700
padding: [0, 140, 0, 0]
size_hint_y: None
height: self.minimum_height
spacing: 150
【问题讨论】:
标签: python python-3.x kivy python-3.6 kivy-language