menator01
Gold Coder
My first test kivy project. It's simple. The only thing I can't seem to get to work is the video thumbnail from web. If it's in the local directory it works.
You can learn more about kivy from here.
test.py
test.kv
You can learn more about kivy from here.
test.py
Python:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.videoplayer import VideoPlayer
from kivy.uix.image import Image
# Define the Screens
class Window1(Screen):
pass
class Window2(Screen):
pass
class Window3(Screen):
pass
class PlayVideo(Screen):
pass
# Window Manager handles all screens
class WindowManager(ScreenManager):
pass
class MyApp(App):
def build(self):
return Builder.load_file('test.kv')
if __name__ == '__main__':
app = MyApp()
app.run()
test.kv
Code:
WindowManager:
Window1:
Window2:
Window3:
PlayVideo:
<PlayVideo>:
name: 'video_window'
BoxLayout:
orientation: 'vertical'
spacing: 50
VideoPlayer:
source: 'https://my-python.org/videos/my.mp4'
state: 'stop'
size_hint_y: None
height: root.height - 125
thumbnail: 'https://my-python.org/videos/my.png'
GridLayout:
cols: 3
row_force_default: True
row_default_height: 40
col_force_default: True
col_default_width: 100
spacing: 10
padding: 10
Button:
text: 'Goto 1'
font_size: 20
on_release:
app.root.current = 'window1'
root.manager.transition.direction = 'up'
Button:
text: 'Goto 2'
font_size: 20
on_release:
app.root.current = 'window2'
root.manager.transition.direction = 'up'
Button:
text: 'Goto 3'
font_size: 20
on_release:
app.root.current = 'window3'
root.manager.transition.direction = 'up'
<Window1>:
name: 'window1'
canvas.before:
Color:
rgba: (180/255, 50/255, 30/255, 1)
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: 'vertical'
spacing: 50
Label:
text: 'Window 1'
font_size: 32
size_hint_y: None
height: root.height - 125
GridLayout:
cols: 3
row_force_default: True
row_default_height: 40
col_force_default: True
col_default_width: 100
spacing: 10
padding: 10
Button:
text: 'Goto 2'
font_size: 20
on_release:
app.root.current = 'window2'
root.manager.transition.direction = 'left'
Button:
text: 'Goto 3'
font_size: 20
on_release:
app.root.current = 'window3'
root.manager.transition.direction = 'left'
Button:
text: 'Play Video'
font_size: 20
on_release:
app.root.current = 'video_window'
root.manager.transition.direction = 'down'
<Window2>:
name: 'window2'
canvas.before:
Color:
rgba: (10/255, 150/255, 330/255, 1)
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: 'vertical'
size: root.width, root.height
Label:
text: 'Window 2'
font_size: 32
size_hint_y: None
height: root.height - 125
GridLayout:
cols: 3
row_force_default: True
row_default_height: 40
col_force_default: True
col_default_width: 100
spacing: 10
padding: 10
Button:
text: 'Goto 1'
font_size: 20
on_release:
app.root.current = 'window1'
root.manager.transition.direction = 'right'
Button:
text: 'Goto 3'
font_size: 20
on_release:
app.root.current = 'window3'
root.manager.transition.direction = 'left'
Button:
text: 'Play Video'
font_size: 20
on_release:
app.root.current = 'video_window'
root.manager.transition.direction = 'down'
<Window3>
name: 'window3'
canvas.before:
Color:
rgba: (10/255, 90/255, 30/255, 1)
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
orientation: 'vertical'
size: root.width, root.height
Label:
text: 'Window 3'
font_size: 32
size_hint_y: None
height: root.height - 125
GridLayout:
cols: 3
row_force_default: True
row_default_height: 40
col_force_default: True
col_default_width: 100
spacing: 10
padding: 10
Button:
text: 'Goto 1'
font_size: 20
on_release:
app.root.current = 'window1'
root.manager.transition.direction = 'right'
Button:
text: 'Goto 2'
font_size: 20
on_release:
app.root.current = 'window2'
root.manager.transition.direction = 'right'
Button:
text: 'Play Video'
font_size: 20
on_release:
app.root.current = 'video_window'
root.manager.transition.direction = 'down'