python-3.x - Kivy 使用两个文件 .kv
问题描述
我正在尝试通过我的 .py 代码上的函数来切换 kv 文件。在我的第一个 kivy 代码中,屏幕很少,在我的第二个 kivy 代码中,有一个 swipebutton@carausel。有什么方法可以连接这两个文件。我发布了一个示例:<Screen1> id:_screen1
在另一个文件上有:<SwipeButton@Carousel>
. 我希望有人可以帮助我这是我卸载第一个文件并加载第二个文件时收到的输出,它不会破坏代码:
` 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
解决方案
如果这两个kv
文件没有重新定义相同的类,那么您可以同时加载它们。
如果这两个kv
文件确实重新定义了相同的类,那么您可以使用Builder.unload_file()在加载另一个之前卸载一个。请注意,加载/卸载kv
文件不会影响已创建的 Widget,只会影响更改后创建的 Widget。
推荐阅读
- javascript - JS中的长版函数
- sharepoint - SharePoint:获取列表标题或 URL (JSLink)
- objective-c - 在目标 c 中声明 swift 协议委托变量时出错
- android - 在循环中以编程方式显示线性布局
- javascript - prop() 不改变 id 值
- python - 具有可变时间窗口的 Pandas groupby 聚合
- handlebars.js - 覆盖 compodoc 模板
- r - ggplot2 - 正确地将奇数个图排列成一个图形
- java - 如何在给定自定义 ZoneRules 的情况下创建 ZoneId
- python - 在没有 jupyter 自动启动的情况下使用 docker 映像