1 回答
TA贡献1818条经验 获得超8个赞
您应该使用 root 或应用程序,而不是同时使用两者。在你的例子中,它将是应用程序,因为你的函数在应用程序类中:
on_press: app.clk()
当然,它不会自行更新,您可以更新全局变量,但不会更新本地变量。试试这个:
class RootWidget(GridLayout):
def __init__(self, **kwargs):
super(RootWidget, self).__init__(**kwargs)
try:
dataget()
except:
print('Error')
dataget()
# make a function to be able to call it
def update_values(self):
self.posterurl = movie["full-size cover url"]
self.showline1 = title + "\n" + str(year) + " - " + str(rating) + "\n" + str(runtime) + " minutes" + " - " + genre
self.showline2 = "Director: " + directStr + "\n" + "\n" + "Writers: " + writerStr
self.showline3 = "Cast: " + actors
self.showline4 = "Summary: " + "\n" + str(summary)
class MyApp(App):
def build(self):
# you will need that object later so put in into variable
self.rw = RootWidget()
# call update function
self.rw.update_values()
return self.rw
def clk(self):
try:
dataget()
# after you get new values update the variables connected to widgets
self.rw.update_values()
except:
print('Error')
dataget()
这应该有效。如果它不会,我会告诉你艰难的方式。
添加回答
举报