I'm doing a proyect about an app with Kivy and i have a few problems with it. The first problem is to add more checkboxes to the MainScreen. At the moment the mainscreen has 4 checkboxes with 1 label for chbx and i need to have 13 checkboxes. When i try to add the same code the kivy app doesn't run, I don't know why, is very strange. The code of the program is:
# -*- 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
import filtro
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=filtro.dic(0)
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()
Filtro is another program which will work with the results of the textinput, but i don't know how to save the textinput that are write in the second Screen. I have tried to save it in the variable t, but the print return an empty list. To summarize, the first problem i have is adding more checkboxes (i need 13 no 4) and the second problem is saving the textinput of the second screen in the list t or something similar, because in the next step i will need the dictionary with the booleans and the list t. If someone knows how to solve this problems,It would be very helpful for my proyect. Thanks a lot.
Aucun commentaire:
Enregistrer un commentaire