伝わりやすいタイトルが思いつかず、変なタイトルとなってしまいました。
質問です。ボタン「Parents : hello()」を押した時、Parentsクラスのhello()を実行したいです。
root.hello()やapp.hello()などが使えず「on_press: Parents.hello()」と記述してみましたが駄目でした。(NameError: name 'Parents' is not defined)
クラスがobjectだから駄目なのでしょうか?
アドバイスをいただけないでしょうか。よろしくお願いします。
Python
1from kivy.app import App 2from kivy.uix.boxlayout import BoxLayout 3 4class MainFrame(BoxLayout): 5 def __init__(self, **kwargs): 6 super().__init__(**kwargs) 7 8 9class Parents(object): 10 def __init__(self): 11 print("親クラスの初期化") 12 13 def hello(self): 14 print("親クラスのhello()")
KV
1#:kivy 1.10.0 2MainFrame: 3 4<MainFrame>: 5 orientation: "vertical" 6 Label: 7 text: "label" 8 BoxLayout: 9 Button: 10 text: "Parents : hello()" 11 on_press: Parents.hello()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/04 09:43
2018/02/04 09:50