如何在Kivy App python中添加更多CheckBox?

时间:2016-03-15 21:53:17

标签: android python checkbox kivy

我正在与Kivy做一个关于应用程序的项目,我遇到了一些问题。第一个问题是在主屏幕上添加更多复选框。目前主屏幕有4个复选框,带有1个标签复选框,我需要有13个复选框。当我尝试添加相同的代码时,kivy应用程序无法运行,我不知道为什么,非常奇怪。该计划的代码是:

{
  name: 'validationScore',
  depends: ['childRecords'],
  type: 'number',
  persist: false,
  convertOnSet: true,
  convert: function(val, rec){
    // here we have access only to direct record field, and not the association association !

    // we can use data directly in the calculation
    children = rec.get('childRecords');

    // or build a fake store in order to easily parse them
    children = Ext.create('Ext.data.Store', {
      model: 'Namespace.model.ChildModel',
      data: rec.get('childRecords')
    })

    // ... calculate whatever

    return result;
  }
}

这是洞穴代码。在第二个屏幕中,用户可以选择一些字段并将textinput保存在变量# -*- coding: utf-8 -*- from kivy.app import App from kivy.lang import Builder from kivy.uix.screenmanager import ScreenManager, Screen from kivy.uix.textinput import TextInput from kivy.uix.label import Label from kivy.uix.gridlayout import GridLayout from kivy.uix.button import Button from kivy.properties import DictProperty Builder.load_string(''' <Root>: MainScreen: name: 'main' AnotherScreen: name: 'another' <MainScreen>: GridLayout: cols: 2 Label: text: "Select Subjects" font_size: 15 Label: text: " " CheckBox: on_active:root.ping('240031',self.active) Label: text: "Electromagnetisme" CheckBox: on_active:root.ping('240033',self.active) Label: text: "Materials" CheckBox: on_active:root.ping('240052',self.active) Label: text: "Termodinàmica" CheckBox: on_active:root.ping('240053',self.active) Label: text: "Electrotècnia" Button: text: "Exit" background_color: .7, .7, 6, 1 on_release:root.parent.current='another' Button: text: "Run" font_size: 24 background_color: .7, .7, 1, 1 on_release: root.parent.current='another' <AnotherScreen>: GridLayout: id: container cols: 2 ''') class MainScreen(Screen): def __init__(self, **kw): super(MainScreen, self).__init__(**kw) self.a = App.get_running_app() self.e={} def ping(self, n, value): self.a.big_dict[n] = value class AnotherScreen(Screen): def on_pre_enter(self, *args): i={'240031':A,'240033':B,'240052':C,'240053':D} t=[] a = App.get_running_app() self.ids.container.add_widget(Button(text='Assignatura',background_color=[0,1,1,1])) self.ids.container.add_widget(Button(background_color=[0,1,1,1],text='Escriu Grup')) for k,v in a.big_dict.iteritems(): if v: self.ids.container.add_widget(Label(text=k+' '+i[k].encode("utf-8"))) self.k=TextInput(multiline=False) t.append(self.k.text) self.ids.container.add_widget(self.k) def run(self): print t b1=Button(text='Exit',background_color=[0,1,0,1]) self.ids.container.add_widget(b1) b2=Button(text='Run',background_color=[0,1,0,1]) self.ids.container.add_widget(b2) b1.bind(on_press=exit) b2.bind(on_release=run) class Root(ScreenManager): pass class SimpleKivy(App): big_dict = DictProperty({'240031':False,'240033':False,'240052':False,'240053':False}) def build(self): return Root() SimpleKivy().run() 中,将结果打印在python屏幕中。如果有人知道如何在主屏幕中添加更多复选框,那将非常有用。

0 个答案:

没有答案