For Windows, we provide what we call a ‘portable package’. You don’t have to install anything “system” wide. Just unzip & run:
-
Download the latest version from http://kivy.org/#download
-
Unzip the package
-
Then, in the unzipped package, you have a script called kivy.bat, use it for launching any kivy application as described below
Start a Kivy Application
Send-to method
You can launch a .py file with our Python using the Send-to menu:
-
Copy the kivy.bat in the Clipboard
-
Open the explorer, and to go the address ‘shell:sendto’
-
You should get the special windows directory SendTo
-
Paste the previously copied kivy.bat as a shortcut
-
Rename it to Kivy <kivy-version>
Then, you can execute application by doing a right click on the .py file -> “Send To” -> “Kivy <version>”.
Double-click method
There are some simple steps that you need to do once in order to be able to launch any kivy application by just double-clicking it:
- Right click on the main python file (.py ending) of the application you want to launch
- From the context menu that appears, select Open With
- Browse your hard disk drive and find the file kivy.bat from the portable package. Select it.
- Select “Always open the file with...” if you don’t want to repeat this procedure every time you double click a .py file.
- You are done. Open the file.
The next time you double click a .py file, it will be executed with the version of python that Kivy ships with.
On Windows we have to ship our own version of Python since it’s not installed by default on Windows (unlike Mac OS X and Linux). By following the steps above, you will set Kivy’s version of Python as the default for opening .py files for your user. Normally this should not be harmful as it’s just a normal version of Python with the necessary third party libraries added to the module search path. If you do encounter unexpected problems, please Contact Us.
Start from Command-Line
If you just want to use or develop with the latest stable kivy version, we offer an alternative way with a console. You need a minimalist GNU system installed on your system. Use msysGit.
When you install msysGit, you must select theses options:
- Don’t replace windows shell
- Checkout as-is, commit as-is (no CLRF replacement!)
You’ll have an icon “Git bash” on your desktop, this is the console we want:
- Start “Git bash”
- cd <directory of portable kivy>
- source kivyenv.sh <full directory path of portable kivy> # (don’t use .)
You are now ready to launch python/kivy from the command-line! Just do:
python <filename.py>
Also, all other scripts and binaries are available, such as:
- cython
- gcc / make...
- easy_install
- gst-inspect-0.10
Use development Kivy
Using the latest development version can be risky. You might encounter issue during the development. If you hit any bug, please report it.
If you want to use the latest development version of Kivy, you can follow theses step:
-
Download and install Kivy for windows as the explained before
-
Go into the portable Kivy directory, where is located Python, Mingw, kivy.bat etc.
-
Rename the kivy directory to kivy.stable
-
Go on github, and download the latest development version of Kivy
-
Extract the zip into the Kivy portable directory
-
Rename the directory named “kivy-<some hash>” to just “kivy”
-
Launch kivy.bat
-
Go to the Kivy portable directory/kivy
-
Type:
make force
-
That’s all, you have a latest development version!
Package Contents
The latest Windows package contains:
- Latest stable kivy version
- Python 2.7.1
- Glew 1.5.7
- Pygame 1.9.2
- Cython 0.14
- MinGW
- GStreamer
- Setuptools
//Kivy的安装
在此,我只介绍有关Windows的安装,在其他平台下的安装由于我还没有具体的环境,所以也不知道具体会遇到什么问题,就介绍出来了.
首先,我们要先下载在Windows安装包,里面包含了我们之后所需要的全部的三方类库.
然后,就是解压到你想要它在的任何地方.
最后,将解压后的一个批处理文件加到你的右键菜单中.
- 找到的解压目录
- 找到Kivy.bat文件
- 复制这个文件
- 在你的资源浏览器中的地址栏中,输入shell:sendto,这会打开一个文件夹
- 把你黏贴你复制的Kivy.bat文件的快捷方式在这里
- 找到一个 .py 文件,右键→发送到,你应该就可以看到一个Kivy*的选项了
Hello World
安装完成Kivy之后,下面让我们按照国际惯例来写一个Hello World程序,以标明从此之后,我们就要开始Kivy之旅了!
import kivy kivy.require('1.4.1') from kivy.app import App from kivy.uix.button import Button class MyApp(App): """docstring for MyApp""" def build(self): return Button(text='Hello World') if __name__ == '__main__': MyApp().run()
运行代码
我们将上面的代码保存为kivy_helloworld.py,然后右键→发送到Kivy*,我们就会看到下面的结果了!
解释
关于上面代码的解释,我也只是一知半解的,所以我就直接用官网上面对这段代码的解释了.
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.首先,我们导入Kivy,然后检查最近被安装的版本是否支持我们的应用程序。如果不支持,一个异常江北自动抛出,然后保护你的应用程序在运行时崩溃。你可以阅读有关kivy.requier()函数的文档来获得更多的信息。 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.我们引入App类,以便能够继承它。通过继承这个类,你自己的类获得几个我们已经为你开发出来用于确认已经被Kivy认识到得特性。
Next, we import the Button class, to be able to create an instance of a button with a custom label.下一步,我们导入Button类,以能够创建一个伴随有一个label的按钮的实例。
Then, we create our application class, based on the App class. We extend the build() function to be able to return an instance of Button. This instance will be used as the root of the widget tree (because we returned it).然后,我们创建我们的基于App类的应用程序类。我们扩展build()方法以便返回一个Button的实例.这个实例被用于作为widget树的根(因为我们返回它).
Finally, we call run() on our application instance to launch the Kivy process with our application inside.最后,我们再我们的应用程序实例中调用run()以启动Kivy在内部处理我们的应用程序.
You’ll have an icon “Git bash” on your desktop, this is the console we want:
- Start “Git bash”
- cd <directory of portable kivy>
- source kivyenv.sh <full directory path of portable kivy> # (don’t use .)
You are now ready to launch python/kivy from the command-line! Just do:
python <filename.py>
Also, all other scripts and binaries are available, such as:
- cython
- gcc / make...
- easy_install
- gst-inspect-0.10
Use development Kivy
Using the latest development version can be risky. You might encounter issue during the development. If you hit any bug, please report it.
If you want to use the latest development version of Kivy, you can follow theses step:
-
Download and install Kivy for windows as the explained before
-
Go into the portable Kivy directory, where is located Python, Mingw, kivy.bat etc.
-
Rename the kivy directory to kivy.stable
-
Go on github, and download the latest development version of Kivy
-
Extract the zip into the Kivy portable directory
-
Rename the directory named “kivy-<some hash>” to just “kivy”
-
Launch kivy.bat
-
Go to the Kivy portable directory/kivy
-
Type:
make force
-
That’s all, you have a latest development version!
Package Contents¶
The latest Windows package contains:
- Latest stable kivy version
- Python 2.7.1
- Glew 1.5.7
- Pygame 1.9.2
- Cython 0.14
- MinGW
- GStreamer
- Setuptools