import kivy
kivy.require('1.11.1')
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import Screen, ScreenManager, FadeTransition
from kivy.uix.widget import Widget
from kivy.graphics import Line, Color
from random import random
class PinterShow(Widget):
def on_touch_down(self, touch):
global TheCanvas
TheCanvas = self.canvas
with TheCanvas:
Color(random(),random(),random())
touch.ud['line'] = Line(points=(touch.x, touch.y))
def on_touch_move(self, touch):
touch.ud['line'].points += [touch.x, touch.y]
def ClearCanvas(self):
print('1')
TheCanvas.clear()
class MainScreen(Screen):
pass
class AnotherScreen(Screen):
pass
class ScreenManagement(ScreenManager):
pass
class SimpleKivy(App):
def build(self):
return Builder.load_file('SimpleKivy.kv')
if __name__ == '__main__':
SimpleKivy().run()
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
#: import GridLayout kivy.uix.gridlayout.GridLayout
ScreenManagement:
transition: FadeTransition()
MainScreen:
AnotherScreen:
<MainScreen>:
name: 'main'
Button:
on_release: app.root.current = 'other'
text: 'next screen'
font_size: 40
<AnotherScreen>:
name: 'other'
FloatLayout:
PinterShow:
id: ps
Button:
text: 'back home'
font_size: 20
color: 0,1,0,1
size_hint: 0.2, 0.1
pos_hint: {'buttom': 0, 'buttom':0}
on_release: app.root.current = 'main'
Button:
text: 'clear'
font_size: 20
color: 0,1,0,1
size_hint: 0.2, 0.1
pos_hint: {'x': 0.2, 'buttom':0}
on_release: ps.ClearCanvas()
title=SimpleKivy
author=Kiveam
orientation=landscape
from random import random, randrange
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Line
from kivy.clock import Clock
class RaysWidget(Widget):
def _new_line(self):
x = 0
y = 0
line = [x,y]
for i in range(200):
x += randrange(50)
y += randrange(100)
line.append(x)
line.append(y)
with self.canvas:
Color(random(), random(), 1)
Line(points=line)
def new_lines(self,dt):
self.canvas.clear()
for i in range(100):
self._new_line()
class RaysApp(App):
def build(self):
rays = RaysWidget()
Clock.schedule_interval(rays.new_lines, 0.2)
return rays
if __name__ == '__main__':
RaysApp().run()
title=Rays
author=Nobody
orientation=portrait