public class java { public static void main(String[] args) { System.out.println("Hello World"); } }
from kivy.app import App from kivy.uix.button import Button class TestApp(App): def build(self): return Button(text='Hello World') TestApp().run()
# test.py import kivy from kivy.app import App class TestApp(App): pass TestApp().run()
# test.kv Button: text: 'Hello world'
package com.mkyong.android; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloWorldActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView text = new TextView(this); text.setText("Hello World"); setContentView(text); } }
# =========== my.kv <HelloWorld>: BoxLayout: Label: id: label text: 'Kivy Sample App' Button: text: 'Click Me' on_press: root.change_text() # =========== my.py from kivy.app import App from kivy.uix.boxlayout import BoxLayout class MyApp(App): def build(self): return HelloWorld() class HelloWorld(BoxLayout): def change_text(self): self.ids.label.text = 'Hello Wolrd!' MyApp().run()
main.py # Your main application file android.txt # Some info Kivy requires about your app on android
title=<Application Title> author=<Your Name> orientation=<portrait|landscape>
my_list = ['K1', 3.14, str] my_list.append(1) my_list.append(10) my_list.append(15) my_list.remove(3.14) print len(my_list) # 5 print my_list # ['K1', str, 1, 10, 15] print my_list[0] # K1
founded_year = { 'Google': 2998, 'Mi©ro$oft': 1975, 'Apple': 1976, 'Facebook': 2004 } founded_year['Google'] = 1998 print founded_year['Apple'] # 1976 print founded_year # {'Google': 1998, 'Mi©ro$oft': 1975, 'Apple': 1976, 'Facebook': 2004} print founded_year.keys() # ['Google', 'Mi©ro$oft', 'Apple', 'Facebook']
company_info = { 'Google': {'founded_year': 1998, 'ceo': 'Larry Page', 'employees': 55030}, 'Mi©ro$oft': {'founded_year': 1975, 'ceo': 'Satya Nadella', 'employees': 128076}, 'Apple': {'founded_year': 1976, 'ceo': 'Tim Cook', 'employees': 98000}, 'Facebook': {'founded_year': 2004, 'ceo': 'Mark Zuckerberg', 'employees': 8348}, }
This code can be cleaner
self.cols = 8 for company, info in company_info.items(): self.add_widget(Label(text='Name: ')) self.add_widget(Label(text=company)) self.add_widget(Label(text='Founded Year: ')) self.add_widget(Label(text=info['founded_year'])) self.add_widget(Label(text='CEO: ')) self.add_widget(Label(text=info['ceo'])) self.add_widget(Label(text='Employees: ')) self.add_widget(Label(text=info['employees']))
import sqlite3 db = sqlite3.connect('db.sqlite') db.execute('INSERT INTO members VALUES ("Gholi", "Kheshtak Zade")').commit() members = db.execute('SELECT * FROM members').fetchall()
CREATE TABLE companies (company_name TEXT, founded_year TEXT, ceo TEXT, employees TEXT); INSERT INTO companies VALUES ('Google', 1998, 'Larry Page', 55030); INSERT INTO companies VALUES ('Mi©ro$oft', 1975, 'Satya Nadella', 128076); INSERT INTO companies VALUES ('Apple', 1976, 'Tim Cook', 98000); INSERT INTO companies VALUES ('Facebook', 2004, 'Mark Zuckerberg', 8348);
db = sqlite3.connect('db.sqlite') company_info = db.execute('SELECT * FROM companies').fetchall() self.cols = 8 for company in company_info: self.add_widget(Label(text='Name: ')) self.add_widget(Label(text=company[0])) self.add_widget(Label(text='Founded Year: ')) self.add_widget(Label(text=company[1])) self.add_widget(Label(text='CEO: ')) self.add_widget(Label(text=company[2])) self.add_widget(Label(text='Employees: ')) self.add_widget(Label(text=company[3]))
You can use android classes using PyJnius
from time import sleep from jnius import autoclass Hardware = autoclass('org.renpy.android.Hardware') print 'DPI is', Hardware.getDPI() Hardware.accelerometerEnable(True) for i in range(20): print Hardware.accelerometerReading() sleep(.1)