- Kivy Blueprints
- Mark Vasilkov
- 223字
- 2021-08-06 19:18:45
Hello, Kivy
When learning a new programming language or technology, the first thing demonstrated to students is traditionally a "hello, world" program. This is how it looks in Python:
print('hello, world')
The Kivy version of a "hello, world" is a little lengthier and consists of two files, namely, a Python module and a .kv
layout definition.
Code
A Kivy application's entry point is customarily called main.py
, and its contents are as follows:
from kivy.app import App class HelloApp(App): pass if __name__ == '__main__': HelloApp().run()
As you can see, this takes Kivy's App
class, adds absolutely nothing to it, and calls run()
.
Layout
A layout file is typically named after the application class, in this case HelloApp
, sans the App
suffix and in lowercase: hello.kv
. It contains the following lines:
Label: text: 'Hello, Kivy'
This is a very simple Kivy layout definition consisting of a single widget, Label
, with the desired text inside. Layout files allow building complex widget hierarchies in a concise, declarative fashion, which is clearly not displayed here, but will be heavily used over the course of this book.
If we run the program now (refer to the Installing and running Kivy section for details), this is what we'll get:

Our first application powered by Kivy
Now you're ready to move on to the first chapter and start writing real programs.
- MySQL數據庫管理實戰
- Web交互界面設計與制作(微課版)
- 趣學Python算法100例
- 看透JavaScript:原理、方法與實踐
- FFmpeg入門詳解:音視頻原理及應用
- Hands-On Automation Testing with Java for Beginners
- D3.js 4.x Data Visualization(Third Edition)
- Go并發編程實戰
- Python忍者秘籍
- Julia高性能科學計算(第2版)
- OpenCV 4計算機視覺項目實戰(原書第2版)
- 好好學Java:從零基礎到項目實戰
- Python機器學習之金融風險管理
- 深度實踐KVM:核心技術、管理運維、性能優化與項目實施
- Puppet:Mastering Infrastructure Automation