0

我已经使用 firebase python 库从 firebase 获得了这个 json 响应。一切都是通过我很难解码对字符串的 json 响应来实现的,所以我可以在 tkinter 中查看它们。任何帮助都会非常感谢。

import requests
from firebase import firebase
from Tkinter import *

firebase = firebase.FirebaseApplication('https://-----', None) #hiding the url for security
message = firebase.get('/message', None)
name = firebase.get('/name', None)

print("The message is: ",message," and it's from ",name)


master = Tk()
showmessage = message," from ", name
w = Label(master, text=showmessage)
w.pack()

mainloop()

我得到的看起来像这样

#printing
('The message is: ', '"this is my message"', " and it's from ",'from a name')

#in tkinter
{"this is my message"}{"from a name"}
4

2 回答 2

0

您想showmessage自己获取字符串的值吗?现在你正在用逗号制作一个元组,所以你可以添加字符串(连接),或者使用格式化......

# just join the strings...
showmessage = message + " from " + name

# or string formatting
showmessage = "{0} from {1}".format(message,name)

无论哪种情况,showmessage现在都应该是一个包含this is my message from from a name(以您在问题中显示的方式...)的字符串

于 2013-10-19T03:09:58.170 回答
0

请尝试以下几行:

print("The message is: {} and it's from {}".format(message,name))


showmessage = message+" from "+ name
w = Label(master, text=showmessage)
于 2013-10-19T03:10:29.097 回答