【发布时间】:2020-11-27 16:25:22
【问题描述】:
我想在 kivy 标签中打印一个列表,但是当我运行代码时,它只显示列表的第一行。如何让 kivy 打印整个列表?
from kivy.uix.label import Label
from kivy.uix.screenmanager import ScreenManager,Screen
Import requests
from kivy.lang import Builder
from kivy.uix.scrollview import ScreollView
from kivymd.uix.button import RoundFlatButton
from kivymd.uix.snackbar import Snackbar
from kivy.app import App
Build.load_string('''
<Page>:
ScrollView:
Label:
id: label
text: ''
height: self.texture_size[1]
text_size: self.width, None
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
font_size: 20
size_hint: 1, 4
MDRoundFlatButton:
text: 'push'
pos_hint: {'center_x': .5, 'center_y': .5}
on_press: robot.problem()
'''
Class Page(Screen):
def __init__(self, **kwargs):
súper(Page, self).__init__(**kwargs)
def problem(self):
try:
objetivo = requests.get(url=self.ids.t1.text)#textinput
header = dict(objetivo.headers)
for x in header:
self.ids.label.text = x + ' : ' + header[x]
return self.ids.label.text
except:
self.ids.label.text = ''' ERROR
(https://www.example.com)'''
self.ids.labe.text = 'swipe'
Snackbar(text=' URL ERROR!').show()
return self.ids.label.text
Class App(App):
def build(self, **kwargs):
self.theme_cls.theme_style = 'Dark'
H = ScreenManager()
G = Page(mame='hello')
H.add_widget(G)
return H
App().run()
它只显示了一行代码,它应该显示完整的列表,请帮助!
【问题讨论】: