kivyでインスタンス?をまたいで変数代入ができない
kivyで簡単なプログラムを試しに作っていたんですが
題にあるよう、インスタンス?をまたいでの変数代入を行うとエラーがおきます
TypeError: 'kivy.properties.DictProperty' object has no attribute '__getitem__'
class pullscreen(Screen):
def clicked(self):
x = np.random.randint(1,10,1)
if x == 5:
result.ids["res"].text = "1"
elif x % 2 == 0:
result.ids["res"].text = "2"
else:
result.ids["res"].text = "3"
sm.current = "ans"
class result(Screen):
def back(self):
sm.current = "pull"
self.idsとするとそのインスタンス内の変数を指定するため望む結果が得られません。
どうすれば良いのでしょうか?よろしくお願いします
pyファイル
from kivy.config import Config
Config.set("graphics", "resizable", False)
Config.set("graphics", "width", 640)
Config.set("graphics", "height", 480)
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
import numpy as np
sm = ScreenManager()
class pullscreen(Screen):
def clicked(self):
x = np.random.randint(1,10,1)
if x == 5:
result.ids["res"].text = "1"
elif x % 2 == 0:
result.ids["res"].text = "2"
else:
result.ids["res"].text = "3"
sm.current = "ans"
class result(Screen):
def back(self):
sm.current = "pull"
class Amidakuji(App):
def build(self):
sm.add_widget(pullscreen(name = "pull"))
sm.add_widget(result(name = "ans"))
return sm
if __name__ == '__main__':
Amidakuji().run()
kvファイル
<PaddingBoxLayout@BoxLayout>:
padding: 20
<pullscreen>:
BoxLayout:
orientation: "vertical"
canvas.before:
Color:
rgba: 0.9,0.9,0.9,1
Rectangle:
pos: self.pos
size: self.size
Label:
text: "Amidakuji"
color: 0,0,0,1
size_hint_y: 0.2
font_size: 32
BoxLayout:
orientation: "horizontal"
Button:
text: "uranau"
on_press: root.clicked()
<result>:
BoxLayout:
orientation: "vertical"
canvas.before:
Color:
rgba: 0.9,0.9,0.9,1
Rectangle:
pos: self.pos
size: self.size
Label:
text: "result"
color: 0,0,0,1
size_hint_y: 0.2
font_size: 32
BoxLayout:
orientation: "horizontal"
Label:
id: res
Button:
text: "mo-ikkai, uranau"
on_press: root.back()