官术网_书友最值得收藏!

Chapter 1. Building a Clock App

This book will walk you through the creation of nine little Kivy programs, each resembling a real-world use case for the Kivy framework. On many occasions, the framework will be utilized together with other Python modules fitting for the task at hand. We will see that Kivy provides a great deal of flexibility, allowing us to solve vastly different problems in a clean, concise manner.

Let's start small. In this chapter, we will build a simple Clock app, similar in concept to the built-in application found in both iOS and Android. In the first part of the chapter, we will create a non-interactive digital clock display and style it, giving our program an Android-ish flat look. We will also briefly discuss the event-driven program flow and a Kivy main loop, introducing timers used to perform recurring tasks, such as updating the screen every frame.

In the second part of this chapter, we will add a stopwatch display and controls, creating a fluid layout suitable for any screen size and orientation. A stopwatch, naturally, needs user interaction, which we are going to implement last.

The important topics introduced in this chapter are as follows:

  • The basics of the Kivy language, a built-in domain-specific language (DSL) used to lay out widgets
  • Styling (and eventually subclassing) built-in Kivy components
  • Loading custom fonts and formatting text
  • Scheduling and listening to events

Our finished program, depicted in the following screenshot, will only be about 60 lines long, split equally between a Python source code and a Kivy language (.kv) interface definition file.

Building a Clock App

The final look of the Clock app we're going to build.

主站蜘蛛池模板: 西藏| 余庆县| 湟源县| 达日县| 太康县| 大安市| 鄂伦春自治旗| 两当县| 读书| 西吉县| 略阳县| 玛多县| 江津市| 钦州市| 新兴县| 齐河县| 杭锦旗| 商洛市| 金溪县| 湘西| 临泉县| 桐城市| 汉沽区| 上蔡县| 黑水县| 临江市| 新安县| 昆明市| 南皮县| 漳平市| 洱源县| 静宁县| 全椒县| 田东县| 克山县| 上林县| 上饶市| 界首市| 黎川县| 霞浦县| 孝昌县|