当前位置:网站首页>Kivy tutorial how to load kV file design interface by string (tutorial includes source code)
Kivy tutorial how to load kV file design interface by string (tutorial includes source code)
2022-07-03 13:20:00 【Knowledge fatness】
Actual combat needs
We sometimes need to be in a py In the file, run the code together with the interface configuration file ?
Solution
We can use Builder.load_string solve .
What is? Builder.load_string
stay Builder Insert a string into and return kv The root widget of the string
load_string ( string , ** kwargs )
Parameters
rulesonly: bool, defaults to False
If True, If you have a root widget in the definition , be Builder Exception will be thrown .filename: str, defaults to None
If specified , Is used for indexing kv File name of the rule .
filename Parameters can be used to uninstall kv Unload the file in the same way kv character string . This can be achieved using pseudo file names , for example :
Build.load_string("""
<MyRule>:
Label:
text="Hello"
""", filename="myrule.kv")
You can uninstall :
Build.unload_file("myrule.kv")
Combat code
from kivy.app import App
from kivy.lang import Builder
# File: clock.kv
KV = '''
BoxLayout:
orientation: 'vertical'
Label:
text: '00:00:00'
'''
class ClockApp(App):
def build(self):
return Builder.load_string(KV)
if __name__ == '__main__':
ClockApp().run()
边栏推荐
- 双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
- The principle of human voice transformer
- [Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter V exercises]
- Spark实战1:单节点本地模式搭建Spark运行环境
- Understanding of CPU buffer line
- SSH登录服务器发送提醒
- C graphical tutorial (Fourth Edition)_ Chapter 18 enumerator and iterator: enumerator samplep340
- regular expression
- [Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [sqlserver2012 comprehensive exercise]
- Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory
猜你喜欢

解决 System has not been booted with systemd as init system (PID 1). Can‘t operate.

Tutoriel PowerPoint, comment enregistrer une présentation sous forme de vidéo dans Powerpoint?

Sword finger offer 14- ii Cut rope II

rxjs Observable filter Operator 的实现原理介绍

今日睡眠质量记录77分

IDEA 全文搜索快捷键Ctr+Shift+F失效问题

Some thoughts on business

106. How to improve the readability of SAP ui5 application routing URL

Multi table query of MySQL - multi table relationship and related exercises

stm32和电机开发(从mcu到架构设计)
随机推荐
Idea full text search shortcut ctr+shift+f failure problem
Servlet
用户和组命令练习
IDEA 全文搜索快捷键Ctr+Shift+F失效问题
Sitescms v3.1.0 release, launch wechat applet
剑指 Offer 17. 打印从1到最大的n位数
剑指 Offer 14- I. 剪绳子
Finite State Machine FSM
2022-01-27 use liquibase to manage MySQL execution version
Server coding bug
Convolution emotion analysis task4
elk笔记24--用gohangout替代logstash消费日志
开始报名丨CCF C³[email protected]奇安信:透视俄乌网络战 —— 网络空间基础设施面临的安全对抗与制裁博弈...
MapReduce实现矩阵乘法–实现代码
[colab] [7 methods of using external data]
Sword finger offer 17 Print from 1 to the maximum n digits
File uploading and email sending
Sitescms v3.0.2 release, upgrade jfinal and other dependencies
MySQL
MySQL functions and related cases and exercises