1
kivyのボタンを押すときに、ボタンとは別のクラスの画面にある関数を呼び出そうとしています。アプリケーションクラスで関数を実行しようとしました。よく問題を抱えていました。ここでは関数は、私が嘘を呼び出すようにしようとしているクラスです。Kivyボタンを使用して別のクラスの関数を呼び出す
# Main screen with button layout
class LandingScreen(Screen):
def __init__(self, **kwargs):
super(LandingScreen, self).__init__(**kwargs)
self.buttons = [] # add references to all buttons here
Clock.schedule_once(self._finish_init)
def ChangePic(self):
self.buttons[1].background_normal = 'folder.png'
そして、ここでは、私はそれを呼び出すようにしようとしているボタンです:
<[email protected]>:
name: 'input_sc'
FloatLayout:
size: 800, 480
id: anchor_1
Label:
text: "What would you like to bind to this button?"
size_hint: (1,.15)
text_size: self.size
pos_hint: {'x': 0.11, 'top': 1}
font_size: 28
font_name: 'Montserrat-Bold.ttf'
Button:
root: 'landing_sc'
id: filebutton
size: 150, 150
size_hint: None, None
background_normal: 'folder.png'
background_down: 'opacity.png'
pos_hint: {'x': 0.11, 'top': .7}
on_release:
root.manager.transition = FadeTransition()
root.manager.transition.duration = 1.5
app.MakeFolder()
root.IfFolder()
root.ChangeToSlide()
私はChangePicを(接頭辞にしている何をすべきか)この場所から呼び出すために?
また、InputScreenクラス内部のLandingScreenクラスのボタンで簡単に操作する方法がありますか?
ありがとうございます!
この変数はメソッドの内部で作成する必要がありますか?私はそれを1つの内部に入れないとエラーになり、app.variableはそれを1つの内部に入れてもそれを見つけることができません。 – John
LandingScreenを参照する変数()あなたのアプリケーションクラスの内部で作成する必要があります 'クラスAppClass命令: some_variable = LandingScreen() デフMakeFolder(自己): #yourコードhere' ので、some_variablesが持っていますLandingScreen()のメソッド some_variable.ChangePic()を実行するだけで、AppClass()内のsome_variableを使ってLandingScreen()メソッドを呼び出すことができます。 しかし、あなたはkvからChangePic()を呼び出したいので、app.some_variableを置く必要があります。 ChangePic() kvのapp.MakeFolder()と同じですが、ChangePic()ではsome_variable – favcau