http://kivy.org/docs/guide/basic.html#quickstart

I followed this tutorial about how to create basic kivy application

*********************

Creating a kivy application is as simple as:

  • sub-classing the App class
  • implementing its build() method so it returns a Widget instance (the root of your widget tree)
  • instantiating this class, and calling its run() method.

Here is an example of a minimal application:

import kivy
kivy.require('1.0.6') # replace with your current kivy version ! from kivy.app import App
from kivy.uix.label import Label class MyApp(App): def build(self):
return Label(text='Hello world') if __name__ == '__main__':
MyApp().run()

You can save this to a text file, main.py for example, and run it.

*********************

LETS EXPLAIN IT!

##################

Kivy App Life Cycle

First off, let’s get familiar with the Kivy app life cycle.

As you can see above, for all intents and purposes, our entry point into our App is the run() method, and in our case that is “MyApp().run()”. We will get back to this, but let’s start from the third line:

from kivy.app import App

It’s required that the base Class of your App inherits from the App class. It’s present in the kivy_installation_dir/kivy/app.py.

Note

Go ahead and open up that file if you want to delve deeper into what the Kivy App class does. We encourage you to open the code and read through it. Kivy is based on Python and uses Sphinx for documentation, so the documentation for each class is in the actual file.

Similarly on line 2:

from kivy.uix.label import Label

One important thing to note here is the way packages/classes are laid out. The uix module is the section that holds the user interface elements like layouts and widgets.

Moving on to line 5:

class MyApp(App):

This is where we are defining the Base Class of our Kivy App. You should only ever need to change the name of your app MyApp in this line.

Further on to line 7:

def build(self):

As highlighted by the image above, show casing the Kivy App Life Cycle, this is the function where you should initialize and return your Root Widget. This is what we do on line 8:

return Label(text='Hello world')

Here we initialize a Label with text ‘Hello World’ and return it’s instance. This Label will be the Root Widget of this App.

Note

Python uses indentation to denote code blocks, therefore take note that in the code provided above, at line 9 the class and function definition ends.

Now on to the portion that will make our app run at line 11 and 12:

if __name__ == '__main__':
MyApp().run()

Here the class MyApp is initialized and it’s run() method called. This initializes and starts our Kivy application.

##################

kivy Create an application的更多相关文章

  1. kivy create a package for Android

    Now that you've successfully coded an app. Now you want to deploy it to Android. So now we would nee ...

  2. maven command to create your application

    How do I make my first Maven project? We are going to jump headlong into creating your first Maven p ...

  3. Java SE series:1. environment configure and Hello world! [We use compiler and packager to create an application!]

    1. cli (command line interface) and gui (graphic user interface) use javahome path, search classpath ...

  4. [NativeScript] Create new application and run emulator

    Install: npm i -g nativescript Create: tns create <app_name> --ng Run: tns emulate ios List al ...

  5. Create First Application

    Node.js创建第一个应用 Node.js开发的目的就是为了用JavaScript编写Web服务器程序, 在使用Node.js时,不仅仅是在实现一个应用,同时还实现了整个HTTP服务器.在创建Nod ...

  6. How do I create an IIS application and application pool using InnoSetup script

    Create an IIS application. Create a new IIS application pool and set it's .NET version to 4. Set the ...

  7. python3使用kivy生成安卓程序

    技术背景 虽然现在苹果占据了很大一部分的市场,但是从销量数据来看,安卓还是占据了人口的高地.这里我们介绍一个用python的kivy+buildozer来进行安卓APP开发的简单教程,从整个过程中来看 ...

  8. cocos2d-x打飞机实例总结(一):程序入口分析和AppDelegate,Application,ApplicationProtocol三个类的分析

    首先,是个敲代码的,基本上都知道程序的入口是main函数,显然,就算在cocos2d-x框架中也一样 我们看看main函数做了什么 #include "main.h" #inclu ...

  9. 应用程序域(Application Domain)

    应用程序域为隔离正在运行的应用程序提供了一种灵活而安全的方法. 应用程序域通常由运行时宿主创建和操作. 有时,您可能希望应用程序以编程方式与应用程序域交互,例如想在不停止应用程序运行的情况下卸载某个组 ...

随机推荐

  1. bootstrap-wysiwyg 结合 base64 解码 .net bbs 图片操作类 (二) 图片裁剪

    图片裁剪参见: http://deepliquid.com/projects/Jcrop/demos.php?demo=thumbnail        一个js插件 http://www.mikes ...

  2. 如何将经纬度利用Google Map API显示C# VS2005 Sample Code

    原文 如何将经纬度利用Google Map API显示C# VS2005 Sample Code 日前写了一篇如何用GPS抓取目前所在,并回传至资料库储存,这篇将会利用这些回报的资料,将它显示在地图上 ...

  3. Atitit.ALT+TAB没反应车and 点击任务栏程序闪烁可是不能切换

    Atitit.ALT+TAB没反应车and 点击任务栏程序闪烁可是不能切换 1. 可能你的Alt+Tab键被别人禁用了,试下以下的方法: 1 2. 为什么要禁用Alt+Tab 1 3. ALT+TAB ...

  4. TML5安全:CORS(跨域资源共享)简介

    来源:http://blog.csdn.net/hfahe/article/details/7730944 前言:像CORS对于现代前端这么重要的技术在国内基本上居然很少有人使用和提及,在百度或者Go ...

  5. Redis 中文入库成功,读取数据写入文件乱码问题

    近期须要用到redis ,可是在编码这个问题上,纠结了非常久.        需求 :每天一个进程将中文文件入库到redis中(不定时更新) ,另外几个进程读取redis中的信息 ,并处理数据结果.使 ...

  6. lua本学习笔记功能

    Lua本学习笔记功能 1.  函数返回 指定任务的主要功能是完成,在这种情况下,函数被用作调用语句.函数可以计算并返回值,在这种情况下,作为分配值表达式语句使用. 语法: funcationfunc_ ...

  7. IOC 容器初始化

    WebApi 插件式构建方案:IOC 容器初始化 一般来说,一个现代化的网站加载流程是这样的:程序集加载后,我们会初始化 IOC 容器,以便于接下来解析对象用. 我们插件式的开发,这一步更为重要.这是 ...

  8. 如何用CSC.exe来编译Visual C#的代码文件

    原文:如何用CSC.exe来编译Visual C#的代码文件 C#的编译过程      如何用CSC.exe来编译Visual C#的代码文件   Csc.exe 编译器的位置路径:C:\Window ...

  9. memcpy源代码

    7月22号去面试开发的职位,面试官先问我在以前项目中写了什么程序.我就巴拉巴拉的说了一堆写过的code,主要还是测试工具和自动化测试代码.之后让我写memcpy的函数,面试官还挺好的,帮我把函数原型都 ...

  10. 解决Shockwave flash在chrome该浏览器崩溃

    越来越多的人开始使用chrome浏览器,很多用户都遇到过flash崩溃.有时重启chrome为了解决,有时不可能使用chrome无论打开什么网站是什么flash.这个问题是非常小的Firefox或IE ...