pyglet教程_kivy官方教程.doc

kivy官方教程

Quickstart

This page explains how to create a simple Kivy “Hello world” program. This assumes you already have Kivy installed. If you do not, head over to the Installation section. We also assume basic Python 2.x knowledge throughout the rest of this documentation.

Create an application

The base code for creating an application looks like this:

import kivy

kivy.require('1.0.6') # replace with your current kivy version !

from kivy.app import App

from kivy.uix.button import Button

class MyApp(App):

def build(self):

return Button(text='Hello World')

if __name__ == '__main__':

MyApp().run()

Save it as main.py.

To run the application, follow the instructions for your operating system:

Linux

Follow the instructions for running Kivy application on Linux:

$ python main.py

Windows

Follow the instructions for running Kivy application on Windows:

$ python main.py

# or

C:\appdir>kivy.bat main.py

Mac OS X

Follow the instructions for running Kivy application on MacOSX:

$ kivy main.py

Android

Your application needs some complementary files to be able to run on Android. See Kivy on Android for further reference.

A window should open, showing a sole button (with the label ‘Hello World’) that covers the entire window’s area. That’s all there is to it.

So what does that code do?

First, we import Kivy, and check if the current installed version will be enough for our application. If not, an exception will be automatically fired, and prevent your application to crash in runtime. You can read the documentation of kivy.require() function for more information.

We import the App class, to be able to subclass it. By subclassing this class, your own class gains several features that we already developed for you to make sure it will be recognized by Kivy.

Next, we import the Button class, to be able to create an instance of a button with a custom label.

Then, we create our application class, based on the App class. We extend the build() function to be able to return a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值