python - python kivy从firebase获取数据以便能够滚动它
问题描述
您好,我正在制作一个软件,有人会问我一个问题,这个问题将被记录到 firebase,然后它会被打印回屏幕上。问题是在问了几个问题之后,我在 firebase 中的录音变长了,这在我的屏幕上水平消失了。
现在的问题是我需要能够滚动这些问题,最好是垂直滚动。还有一种方法可以将firebase字符串解码为简单的文本而不是那么难看。非常感谢您的帮助!!!!
from kivy.app import App
from kivy.lang import Builder
import json
import requests
a=[]
KV = Builder.load_string ("""
ScreenManager:
id: manager
Screen:
BoxLayout:
orientation: 'vertical'
GridLayout:
cols:1
Label:
text: 'Write a JSON string'
TextInput:
size_hint_y: .4
id: JSON
Button:
text: 'Ask me a question . . <3'
on_press:
self.text='Ask another question?'
on_release:
app.patch(JSON.text)
self.text='Ask another question?'
app.set_text()
Button:
text: 'Get & Print Database'
on_release:
app.get()
app.set_text()
Label:
cols:1
id:new_label
Label:
id: my_label
""")
class MyApp(App):
url = 'https://questions-44894-default-rtdb.firebaseio.com/pfpffp.json' # You must add .json to the end of the URL
def patch(self, JSON):
to_database = json.loads(JSON)
requests.patch(url = self.url, json = to_database)
def post(self, JSON):
to_database = json.loads(JSON)
requests.post(url = self.url, json = to_database)
def put(self, JSON):
to_database = json.loads(JSON)
requests.put(url = self.url, json = to_database)
def delete(self, JSON):
requests.delete(url = self.url[:-5] + JSON + ".json")
auth_key = 'bTwFAO5zo89eyXpTu30B4C3Fh2hsw3p3JBDZOgYA' # Refer to the YouTube video on where to find this.
def get(self):
request = requests.get(self.url + '?auth=' + self.auth_key)
#print(type(request))
request.json()
new_label=self.root.ids.new_label
new_label.text= request.text
def set_text(self):
JSON = self.root.ids.JSON
my_label = self.root.ids.my_label
my_label.text = JSON.text
pass
def build(self):
return KV
if __name__ == '__main__':
MyApp().run()
解决方案
推荐阅读
- javascript - 如何从谷歌表格将多个图表添加到 1 个谷歌幻灯片中
- vb.net - 如何加入跳过最后 2 个元素的字符串列表
- python - 将 .kv 类转换为 .py 类
- java - 正则表达式检查字符串是数字还是单词“all”
- powershell - “IIS:当文件已存在时无法创建文件。Exception.Message”通过 SSL 证书和 powershell 创建 https 绑定时
- postgresql - PostgreSQL 表 --data-only 转储占用表大小的两倍以上
- ksqldb - 如何获取 ksqldb 表的当前状态?
- linux - boost::multiindex 和继承
- typescript - 如何限制打字稿中的枚举字符串值
- elasticsearch - 弹性搜索将过滤器应用于聚合数据