Kivy在其他屏幕上调用功能(Kivy call function in other screen)
所以我正在开发一个kivy项目,并为它学习语言(我的意思是python),我在这里有这个小程序。 所以在我的第一个屏幕上有一些语言按钮,但我也有文字在第二页中更改。 我怎样才能在课堂上调用其他课程的功能,或者我应该用不同的方式来改变课本? 任何tipp会有所帮助:)谢谢
class ScreenOne(Screen): def d_language(self): self.hellolabel.text='Hallo' def fr_language(self): self.hellolabel.text='Bonjour' class ScreenTwo(Screen): def d_languagetwo(self): self.otherlabel.text='Zweite seite' def fr_languagetwo(self): self.otherlabel.text='Deuxième page'So I'm working on a kivy project and also learning the language for it (I mean python) and I have this little program here. So there are some language button on my first screen but I also have text to change in the second page. How can I call an other class' function in a class, or should I use a different way to change the textes? Any tipp would be helpful :) thanks
class ScreenOne(Screen): def d_language(self): self.hellolabel.text='Hallo' def fr_language(self): self.hellolabel.text='Bonjour' class ScreenTwo(Screen): def d_languagetwo(self): self.otherlabel.text='Zweite seite' def fr_languagetwo(self): self.otherlabel.text='Deuxième page'最满意答案
您可以使用屏幕管理器转到其他屏幕
def d_language(self): self.hellolabel.text = 'Hallo' #now change the other label s2 = self.manager.get_screen('name of the other screen') #or ... #s2 = self.manager.screens[1] # will also work... s2.otherlabel.text = 'Zweite seite' #or ... #s2.d_languagetwo()...
You can use the screen manager to get to the other screen
def d_language(self): self.hellolabel.text = 'Hallo' #now change the other label s2 = self.manager.get_screen('name of the other screen') #or ... #s2 = self.manager.screens[1] # will also work... s2.otherlabel.text = 'Zweite seite' #or ... #s2.d_languagetwo()...
更多推荐
发布评论