【发布时间】:2017-11-22 12:28:52
【问题描述】:
我用 Python (test.py) 和 kivy (test.kv) 编写了一些代码。
当我运行 test.py 时,男性复选框显示选中,女性复选框未选中,因为我在 test.kv 文件中使用:
active: root.male
但我想从 .py 文件中得到同样的东西。如何从 .py 文件中检查男性复选框?
test.py
from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.properties import ObjectProperty
Window.size = (600, 325)
class UserGroup(Screen):
male = ObjectProperty(None)
female = ObjectProperty(None)
age = ObjectProperty(None)
def insert_data(self):
print('')
class FactUserGroup(App):
def build(self):
self.root = Builder.load_file('test.kv')
return self.root
if __name__ == '__main__':
FactUserGroup().run()
test.kv
<CustomLabel@Label>:
text_size: self.size
valign: "middle"
padding_x: 5
<SingleLineTextInput@TextInput>:
multiline: False
<GreenButton@Button>:
background_color: 1, 1, 1, 1
size_hint_y: None
height: self.parent.height * 0.120
UserGroup
male: chk_male
female: chk_female
GridLayout:
cols: 2
padding : 30,30
spacing: 20, 20
row_default_height: '30dp'
Label:
text: 'Male'
text_size: self.size
valign: 'middle'
CheckBox:
group: 'check'
id : chk_male
active: root.male
Label:
text: 'Female'
text_size: self.size
valign: 'middle'
CheckBox:
group: 'check'
id: chk_female
GreenButton:
text: 'Ok'
GreenButton:
text: 'Cancel'
on_press: app.stop()
有人可以帮我吗?
【问题讨论】:
标签: python python-2.7 kivy kivy-language