我试图打电话"开始"来自AUDIO屏幕
class Audio(Screen):
def start(self):
class MainPage(Screen):
def open1(self, *args):
self.play = ImageButton(source= 'play.png',allow_stretch= True, pos= (600, 850), size_hint= (.2,.1))
self.play.bind(on_press=audio.start()) #How do I call start?
编辑:这只是一个示例代码
答案 0 :(得分:0)
您需要先创建一个类的实例,然后才能调用它的方法。
在Python中,通过使用尾部括号调用类来完成,基本上就像方法调用一样。 话虽如此,改变你的最后一行:
self.play.bind(on_press=audio.start())
到此:
self.play.bind(on_press=Audio().start())
答案 1 :(得分:0)
我认为您应该在屏幕管理器根目录中定义此方法。例如:
library(igraph)
set.seed(1)
sg<-sample_bipartite(10, 5, p=.3)
countries<-c("US","France","China")
V(sg)[type=="TRUE"]$country<-sample(countries,replace=TRUE,5)
V(sg)[type=="FALSE"]$label <- c("a","b","c","d","e","f","g","h","i","j")
V(sg)[type=="TRUE"]$label <- V(sg)[type=="TRUE"]$country
V(sg)$color[1:10] <- rgb(0,1,0,.5)
V(sg)$color[11:15] <- rgb(1,0,0,.5)
plot(sg)
idx <- V(sg)$type==0
res <- lapply(ego(sg, idx, order = 1), function(x)
names(tail(sort(table(V(sg)$country[x[-1]])), 1))
)
V(sg)$country[idx] <- res
unlist(V(sg)$country[V(sg)$label=="a"])
# [1] "China"
unlist(V(sg)$country[V(sg)$label=="e"])
# [1] "US"
unlist(V(sg)$country[V(sg)$label=="c"])
# [1] "China"
如果在按下按钮时调用此方法,我强烈建议您使用Kivy文件定义视图,并使用class RootScreenManager(ScreenManager):
# your class implementation
def start(self):
# your method implementation
class Audio(Screen):
def start(self):
# your code
class MainPage(Screen):
# your code
属性调用start
:
on_press
另一方面,如果您不想要以前的方法,您可以在要定义的方法中创建该类的实例,然后通过以下方法将该方法与您的按钮绑定:
Button:
Image:
source: 'play.png'
size_hint: .2, .1
on_press: app.root.start()
pos: 600, 850