- 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.
- 數(shù)據(jù)庫系統(tǒng)原理及MySQL應(yīng)用教程(第2版)
- TypeScript入門與實(shí)戰(zhàn)
- Intel Galileo Essentials
- 編程的修煉
- Swift 3 New Features
- CKA/CKAD應(yīng)試教程:從Docker到Kubernetes完全攻略
- 軟件項(xiàng)目管理實(shí)用教程
- 大話Java:程序設(shè)計(jì)從入門到精通
- 軟件項(xiàng)目管理實(shí)用教程
- 運(yùn)維前線:一線運(yùn)維專家的運(yùn)維方法、技巧與實(shí)踐
- 零基礎(chǔ)學(xué)HTML+CSS
- Software-Defined Networking with OpenFlow(Second Edition)
- C語言程序設(shè)計(jì)教程
- Ionic3與CodePush初探:支持跨平臺(tái)與熱更新的App開發(fā)技術(shù)
- Android應(yīng)用開發(fā)攻略