Python Kivyを使用しています。
下記のようなコードを書きました。ディレクトリ構造も一応書きました。
目標はAクラススクリーンをBクラスに遷移することですが。
どうしてもScreenManager外のBoxLayoutであるNav_Gridから
画面遷移の指示を出力したかったので、
navigation.pyにてAクラスのget_another_screenメソッドをインスタンス化し、
Navigationクラス内でインスタンス変数に代入する形で実行しようとしました。
その際にこんなエラーを出しました。
Node
1AttributeError: 'NoneType' object has no attribute 'transition'
このエラーの解決方法を教えてください。
|
|
|
|
|
書いたコード
--ディレクトリ構造--
root/
├ main.py
├ my.kv
├ lib/
│ └ init.py
│ └navigation.py
python
1#In main.py (main.pyの中) 2 3#インポート系は省略 4 5class A(Screen): 6 def on_pre_enter(self): 7 print('OK') 8 9class B(Screen): 10 def on_pre_enter(self): 11 print('Entered') 12 13sm = ScreenManager() 14sm.add_widget(A(name='A')) 15sm.add_widget(B(name='B')) 16sm.current = 'A' 17 18class MyApp(App): 19 title = "MyApp" 20 21 def build(self): 22 pass 23 24if __name__ == '__main__': 25 MyApp().run() 26
python
1#In navigation.py (navigation.pyの中) 2 3#インポート系は一部省略 4from kivy.uix.screenmanager import Screen, ScreenManager, NoTransition 5 6class A(Screen): 7 def get_another_screen(self,screen): 8 self.manager.transition = NoTransition() 9 self.parent.current = screen 10 11Gts = A() 12 13class Navigation(ButtonBehavior, BoxLayout): 14 def on_release(self): 15 Nv = self.nv 16 print(Nv) 17 A.get_another_screen(Gts,Nv) 18 A.get_another_screen(Nv) 19 20Builder.load_string(''' 21#...KV系は一部省略 22<Nav_Grid>: 23 Navigation: 24 nv: 'Setting' 25''') 26 27if __name__ == '__main__': 28 from kivy.app import App 29 30 class NavigationApp(App): 31 32 def build(self): 33 pass
python
1# In my.kv 2 3#インポート系は一部省略 4 5BoxLayout: 6 orientation: 'vertical' 7 ScreenManager: 8 A: 9 name: 'A' 10 Label: 11 text: 'This is A' 12 color: 0, 0, 0, 1 13 B: 14 name: 'B' 15 Label: 16 text: 'This is B' 17 color: 0, 0, 0, 1 18 Nav_Grid #Nav_GridはBoxLayoutです。 19 20
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/03 12:18