【问题标题】:Kivy call function in other screen其他屏幕中的 Kivy 呼叫功能
【发布时间】:2018-01-03 11:55:33
【问题描述】:

所以我正在做一个 kivy 项目,同时也在学习它的语言(我的意思是 python),我在这里有这个小程序。所以我的第一个屏幕上有一些语言按钮,但我在第二页也有要更改的文本。如何在一个类中调用其他类的函数,或者我应该使用不同的方式来更改文本?任何提示都会有所帮助:) 谢谢

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'

【问题讨论】:

  • 嗨 Levi,看看 thisthis。另外,您的按钮在哪里?如果可能,添加更多项目代码
  • 感谢您的提示 :) Yoav Glazner 的回答是我一直在寻找的主要内容

标签: python function class oop kivy


【解决方案1】:

您可以使用屏幕管理器进入另一个屏幕

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()

...

【讨论】:

  • 非常感谢。我希望有这样的东西,但我在网上找不到任何东西
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多