Kivy在其他屏幕上调用功能(Kivy call function in other screen)

编程入门 行业动态 更新时间:2024-10-28 09:19:47
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()

...

更多推荐

本文发布于:2023-08-02 21:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1381446.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:功能   屏幕上   Kivy   screen   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!