【发布时间】:2016-09-01 02:58:23
【问题描述】:
我有以下代码:
class MyGridLayout(GridLayout):
def __init__(self, **kwargs):
super(MyGridLayout, self).__init__(**kwargs)
class Board(Widget):
my_layout = ObjectProperty(None)
def __init__(self, **kwargs):
super(Board, self).__init__(**kwargs)
def on_my_layout(self, instance, value):
print self.my_layout.cols
class MyApp(App):
def build(self):
return Board()
if __name__ == '__main__':
MyApp().run()
这是我的 kv 文件:
<Board>:
my_layout: my_layout
MyGridLayout:
id: my_layout
cols: 10
rows: 10
关于方法on_my_layout 我想打印我的MyGridLayout 实例有多少列。但是,它总是返回给我 None。如果我想访问行,它也返回 None 。为了访问MyGridLayout 的行和列的正确值,我必须对我的python 代码或我的kivy 语言进行哪些更改?它必须返回rows = 10 和cols = 10。
【问题讨论】:
标签: python kivy kivy-language