When holding a study session, it seems that there are many cases where the environment construction is stumbled, so make a note. This method is not always the correct answer.
By the way. Kivy is a Python framework for NUI development. It is relatively easy to develop GUI applications that operate cross-platform and support multi-touch.
To build the environment, please download the one suitable for each OS from http://kivy.org/#download.
Windows Building a Windows environment is relatively easy. First of all, run the downloaded Kivy-1.9.0-py \ *. \ *-Win32-x \ * \ . Exe. ( Is the version number, etc.) Then you will have a folder called Kivy-1.9.0-py \ *. \ * -Win32-x \ * \ * in the same directory. The contents are like an image.
Double-click kivy-\ *. \ *. Bat in this to start it. Then, the environment has been set and the command prompt will be launched. After that, move to the directory with the source code
python <file name>.py
It is OK if you execute. (Be careful not to close the command prompt)
It will be convenient if you set various environment variables and paths, but I will omit it this time.
Mac
You can easily build a Mac.
When you open the downloaded Kivy-1.9.0-rev3-osx.dmg, it will be displayed as shown in the image below.
<img width="529" alt="スクリーンショット 2015-11-10 12.04.18.png " src="https://qiita-image-store.s3.amazonaws.com/0/98851/22366017-6fb4-c6f0-ba6d-c4c9e495cc29.png ">
First, let's put Kivy in Applications. Then double-click MakeSymlinks to run it.
After that, start the terminal and type in the following.
``` $ kivy ```
If all goes well, Python should start as shown in the image.
<img width="571" alt="スクリーンショット 2015-11-10 11.50.19.png " src="https://qiita-image-store.s3.amazonaws.com/0/98851/604cb878-14ef-bc6e-3aff-4b8e57ab20e5.png ">
This completes the environment construction.
All you have to do is write the source. Execution
#### **` $ kivy <file name>.py `**
```py
Just do.
Linux(Ubuntu)
How to build an environment on Ubuntu. This time, we will not use an environment such as virtualenv.
First, run the following command
#### **`kivy-team/kivy`**
``` $ sudo add-apt-repository ppa
For Python2, use the following command
```$ sudo apt-get install python-kivy```
For Python3, use the following command
```$ sudo apt-get install python3-kivy```
I haven't tried this, so I don't know, but I think the command can be executed with `` `$ kivy``` or ``` $ python```.
# Try to display Hello World
## First of all, normally
#### **`main.py`**
```py
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.label import Label
class HelloApp(App):
def build(self):
return Label(text='Hello World')
if __name__ == '__main__':
HelloApp().run()
Let's display Hello World using the Kv language, which is also a feature of Kivy. Think of the Kv language as something like CSS.
main.py
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.label import Label
class HelloApp(App):
def build(self):
return Label()
if __name__ == '__main__':
HelloApp().run()
The file name that describes the Kv language should be `hello.kv```. This must be a promise before the App in the class name of ``` class HelloApp (App):` `.
MainApp (App): If it is
, name it
`main.kv```.
hello.kv
#:kivy 1.9.0
<Label>:
text: 'Hello World'
Execution result (slightly increased font size)
This is how to display from environment construction to Hello World. Please feel free to comment if you say "I'm wrong".
Kivy study sessions are also held regularly, so if you are interested ... http://pyky.connpass.com/
Recommended Posts