Reputation: 63
i'm trying to switch kv files by a function on my .py code. In my first kivy code there are few screens and in my second kivy code there is a [email protected] there any way for connect the two files. I post an example: <Screen1> id:_screen1
on another file there is: <SwipeButton@Carousel>
. I hope someone can help me
This is the output received when I unload the first file and load the second, it doesn't break the code:
` class MainApp(MDApp) def build(self): self.title = "Meet!"
if "Colore" in impostazioni:
self.theme_cls.theme_style = impostazioni.get("Colore")["coloresfondo"]
else:
print("Nulla")
self.theme_cls.theme_style = "Light"
if "Nome" in impostazioni:
Nome = impostazioni.get("Nome")["nome"]
print(Nome)
else:
print("Non trovato")
if "Sesso" in impostazioni:
Sesso1 = impostazioni.get("Sesso")["sesso"]
print(Sesso1)
else:
print("Non trovato")
self.theme_cls.primary_palette = "Red"
self.theme_cls.primary_hue = "A700"
self.dativari = [{'id': i, 'data_index': i, 'index': 1, 'height': 48, 'text': str(calendariofile.get(str(i)))} for i in calendariofile]
self.screen = Builder.load_file("num3.kv")
self.root = Builder.load_file("prova.kv")
return self.screen`
#:import C kivy.utils.get_color_from_hex <SwipeButton@Carousel>: text: '' size_hint_y: None height: 48 ignore_perpendicular_swipes: True data_index: 0 min_move: 20 / self.width on__offset: app.aggiorna(root.data_index)#print(root.data_index) #app.update_index(root.data_index, self.index) canvas.before: Color: rgba: C('FFFFFF33') Rectangle: pos: self.pos size: self.size Line: rectangle: self.pos + self.size Button: text: 'delete ({}:{})'.format(root.text, root.data_index) on_press: app.elimina(root.data_index) Label: text: root.text Button: text: 'archive' on_press: app.passachat(root.data_index) RecycleView: data: app.dativari viewclass: 'SwipeButton' do_scroll_x: False scroll_timeout: 100 RecycleBoxLayout: orientation: 'vertical' size_hint_y: None height: self.minimum_height default_size_hint: 1, None
Upvotes: 0
Views: 307
Reputation: 38837
If the two kv
files do not redefine the same classes, then you can just load them both.
If the two kv
files do redefine the same classes, then you can use Builder.unload_file() to unload one before loading the other. Note that loading/unloading kv
files will not affect Widgets already created, it will only affect Widgets created after the change.
Upvotes: 1