[英]How can i use .kv file in different folders?
I don't know how to use.kv file so i just want to summary example.我不知道如何使用 .kv 文件,所以我只想总结示例。 For example let we have 2 folders.例如,让我们有 2 个文件夹。
These folders: src and design.这些文件夹:src 和 design。
src folder contain: main.py src文件夹包含:main.py
design folder contain: main.kv设计文件夹包含:main.kv
I want to know just simple example in this situation.我只想知道这种情况下的简单示例。 How can i access from main.py file to main.kv file.如何从 main.py 文件访问 main.kv 文件。 I researched but i didn't understand very well.我研究过,但我不太了解。 Please just give me a simple example.请给我一个简单的例子。
you can use the Builder object to load all of the.kv files you want.您可以使用 Builder object 加载您想要的所有.kv 文件。
# useful for creating paths from multiple parts
from pathlib import Path, PurePath
#
from kivy.lang import Builder
# load_file can be called multiple times
Builder.load_file(str(PurePath("c:/", "users", "public", "my_lib.kv")))
Builder.load_file(str(PurePath("c:/", "users", "public", "my_wigdet.kv")))
I don't know the reason but in at least one of my apps, I had to load the one.kv file for the main app in a different way.我不知道原因,但至少在我的一个应用程序中,我不得不以不同的方式为主应用程序加载 one.kv 文件。
main_gui_app = App() # substitute your own app creation..
main_gui_app.kv_file = str(Path(*your_path, "main_app.kv"))
main_qui_app.run()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.