kivy Create an application
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- [NativeScript] Create new application and run emulator
Install: npm i -g nativescript Create: tns create <app_name> --ng Run: tns emulate ios List al ...
- Create First Application
Node.js创建第一个应用 Node.js开发的目的就是为了用JavaScript编写Web服务器程序, 在使用Node.js时,不仅仅是在实现一个应用,同时还实现了整个HTTP服务器.在创建Nod ...
- 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 ...
- python3使用kivy生成安卓程序
技术背景 虽然现在苹果占据了很大一部分的市场,但是从销量数据来看,安卓还是占据了人口的高地.这里我们介绍一个用python的kivy+buildozer来进行安卓APP开发的简单教程,从整个过程中来看 ...
- cocos2d-x打飞机实例总结(一):程序入口分析和AppDelegate,Application,ApplicationProtocol三个类的分析
首先,是个敲代码的,基本上都知道程序的入口是main函数,显然,就算在cocos2d-x框架中也一样 我们看看main函数做了什么 #include "main.h" #inclu ...
- 应用程序域(Application Domain)
应用程序域为隔离正在运行的应用程序提供了一种灵活而安全的方法. 应用程序域通常由运行时宿主创建和操作. 有时,您可能希望应用程序以编程方式与应用程序域交互,例如想在不停止应用程序运行的情况下卸载某个组 ...
随机推荐
- MySql绿色版配置及使用详解
原文:MySql绿色版配置及使用详解 最近在做项目开发时用到了MySql数据库,在看了一些有关MySql的文章后,很快就上手使用了.在使用的过程中还是出现了一些问题,因为使用的是绿色免安装版的MySq ...
- Ionic项目中使用极光推送-android
对于Ionic项目中使用消息推送服务,Ionic官方提供了ngCordova项目,这个里面的提供了用angularjs封装好的消息推送服务(官方文档),使用的是GitHub上的 PushPlugin ...
- HDU 3094 A tree game 树删边游戏
叶节点SG值至0 非叶节点SG值至于它的所有子节点SG值添加1 XOR和后 #include <cstdio> #include <cstring> #include < ...
- SqlServer-COMPUTE BY
原文:SqlServer-COMPUTE BY COMPUTE BY子句可以通过同一个select语句即查看明细行,又查看汇总行.可以计算子组的汇总值,也可以计算整个结果集的汇总值 COMPUTE 子 ...
- Objective-C和Swift
在项目中同时使用Objective-C和Swift 苹果发布的Swift语言可以和之前的Objective-C语言同时存在于一个项目中. 可能有人会认为是同一个类文件中既可以有Objective-C也 ...
- css3学习文档
什么是CSS3? CSS3是CSS2的升级版本,3只是版本号,它在CSS2.1的基础上增加了很多强大的新功能. 目前主流浏览器chrome.safari.firefox.opera.甚至360都已经支 ...
- memcpy源代码
7月22号去面试开发的职位,面试官先问我在以前项目中写了什么程序.我就巴拉巴拉的说了一堆写过的code,主要还是测试工具和自动化测试代码.之后让我写memcpy的函数,面试官还挺好的,帮我把函数原型都 ...
- having在Oracle和mysql小点不同
在Oracle中,having一定要结合group by使用,但在mysql中,情况就不一样了.能够单独使用. C:\Documents and Settings\guogang>sqlplus ...
- iOS:由URL成员UIImage
很多时候,我们只能得到URL.然后,需要建立一个UIImage. 在正常情况下,.我们一般通过SDWebImage直接施工UIImageVIew的image,如何使用URL直接施工UIImage它? ...
- [翻译]用Dart塑造Android未来
明天回家,今天下午瞅时间翻译了Cyril Mottier的另外一篇有关Android前景的文章. 原谅地址是:http://cyrilmottier.com/2014/06/12/shaping-th ...